Subject Re: [IBO] TIB_ComboBox dropped on a TIB_Grid
Author Helen Borrie
At 01:07 PM 21-11-01 +0000, you wrote:

> > a) If the grid column has a value AND it matches a value in the
>combox's Items[], then the matching value will be the currently
>displayed text in the editbox portion of the combobox control.
> > b) If the grid column has a value which is not matched in Items[],
>or is null, the editbox of the combobox control will be empty. You
>can drop down the combobox and select an item from the list. Then
>the editbox and the grid cell will show the same text.
>
>Correct, this is what I see. Doesn't it seem problematic to you that
>the grid does not show values not in the combobox's Items[]? What it
>the use of csDropDown then, if I can *enter* any value, but only
>*see* those that are in Items[]?
>Again, the "odd" thing is that the value does show up for the current
>cell.

Mirco,
Either you are missing something, or I am.

You said that the dataset stores the *actual value*, not a linking key, right?
So, if the column value in the selected row matches an item in the list's Items[] AND the dataset is in Edit or Insert mode, you should see the same text in both the grid column and the combobox's edit box.

You said:

"Doesn't it seem problematic to you that the grid does not show values not in the combobox's Items[]? What it the use of csDropDown then, if I can *enter* any value, but only *see* those that are in Items[]?"

Are you saying that, if the value in the grid (either existing, or typed in by the user) does not match an item in the list, then the editbox of the combo should show the user's value? How do you think this could work, if that text is not in the list?

You could write some code that, during editing or inserting, would detect when the user entered a new value, and add that value to the Items[] array. But it would only last until the form was destroyed, since these items are hard-coded, not stored in the database.

One way you could do this, would be to have an unattached ib_cursor that gets all of the latest values from that column each time the changes to the main dataset are committed:

select distinct thatcolumn from gridtable as DESCRIPTION
where thatcolumn is not null and thatcolumn <> ''
order by 1

Have a procedure that which you can call whenever you need to update the combobox list (including at FormCreate):

procedure MyForm.PopulateMyList;
with mycursor, mycombobox do
begin
if active then close;
First;
Items.Clear;
while not EOF do
begin
Items.Add(Fields[0]);
Next;
end;
Close;
end;

Otherwise, for more convenience, use a TIB_LookupCombo, which is "double-data-aware" and will do this task for you automatically.

regards,
Helen

All for Open and Open for All
InterBase Developer Initiative ยท http://www.interbase2000.org
_______________________________________________________