2011. január 30., vasárnap

How to avoid direct input into a TDBGrid when there is a lookup list available


In my TDBGrid, some columns have a picklist. Users can enter any value in these columns, not only values from the picklist. Does anybody know a simple way to prevent this? I would like either to suppress direct input and only allow selection of an existing item of the picklist, or check that input is in the picklist.


procedure DBGridColExit(Sender: TObject);
  S: string;
  with TDBGrid(Sender) do
    if (SelectedField = myfield) and
      (Columns[SelectedIndex].PickList.IndexOf(SelectedField.AsString) = -1) then
      with SelectedField do
        S := AsString;
        AsString := '';
        raise ExceptionCreate(S + ' is not a valid thingummy.' +
          #13'Choose a value from the drop-down list.');

1 megjegyzés: