Board index » delphi » D5 - DBComboBox - Items AND Values?

D5 - DBComboBox - Items AND Values?

Is there anyway that a DBComboBox can operate like a DBRadioGroup (or
even a DBCheckbox) ie Displaying a list of Items to the user, but mapping
the selection (via the Values property) into the table.
Simple Example: DBComboBox with values of Yes, No and Maybe that are
stored as a single character field in the table.

I have been able to simulate this using two string lists plus code to set
and retrieve the values, but I feel there must be a neater way.

All suggestions welcomed.

 

Re:D5 - DBComboBox - Items AND Values?


Look at the RxLibrary version.

Robert

Quote
David Carle <davidca...@clara.net> wrote in message

news:396FBE98.1564@clara.net...
Quote
> Is there anyway that a DBComboBox can operate like a DBRadioGroup (or
> even a DBCheckbox) ie Displaying a list of Items to the user, but mapping
> the selection (via the Values property) into the table.
> Simple Example: DBComboBox with values of Yes, No and Maybe that are
> stored as a single character field in the table.

> I have been able to simulate this using two string lists plus code to set
> and retrieve the values, but I feel there must be a neater way.

> All suggestions welcomed.

Re:D5 - DBComboBox - Items AND Values?


For Boolean fields you can use the DisplayValues property. For integer
fields I always use:

procedure TForm1.Table1SomeFieldGetText(Sender: TField; var Text: String;
DisplayText: Boolean);
begin
  if not Sender.IsNull and
    (Sender.AsInteger >= 0) and
    (Sender.AsInteger < DBComboBox1.Items.Count) then
    Text := DBComboBox1.Items[Sender.AsInteger]
  else
    Text := Sender.AsString;
end;

procedure TForm1.Table1SomeFieldSetText(Sender: TField; const Text: String);
var
  i: Integer;
begin
  i := DBComboBox1.Items.IndexOf(Text);
  if i < 0 then
    i := StrToIntDef(Text, -1);
  if i >= 0 then
    Sender.AsInteger := i
  else
    Sender.Clear;
end;

"David Carle" <davidca...@clara.net> schreef in bericht
news:396FBE98.1564@clara.net...

Quote
> Is there anyway that a DBComboBox can operate like a DBRadioGroup (or
> even a DBCheckbox) ie Displaying a list of Items to the user, but mapping
> the selection (via the Values property) into the table.
> Simple Example: DBComboBox with values of Yes, No and Maybe that are
> stored as a single character field in the table.

> I have been able to simulate this using two string lists plus code to set
> and retrieve the values, but I feel there must be a neater way.

> All suggestions welcomed.

Other Threads