Subject Re: [IBO] Grid or list selection with only one column
Author Helen Borrie
At 09:17 PM 16/05/2005 +0300, you wrote:
>Hiya.
>
>
>This is probably very simple, I just can't figure it out myself: I want to
>have a list of names in a list, and all detail edits on the same window
>linked to the list so that when the user clicks on the list the edits would
>be filled in. Real easy to do with all columns, with a Query component and a
>Datasource component, except that if the query has many columns (or a very
>simple "select * from...), the list will show all columns as well.
>
>I've tried it with IB_Grid, IB_Listbox and IB_Lookuplist, but can't figure
>out how to force just the columns I want to be shown. Or, do I need to have
>separate queries or datasources, or something? I can hack it by making one
>query to fill the list, and then a second query to fill all the edits when
>the selection in the list changes, but somehow I feel that there is probably
>an easier way...

Use the FieldsVisible property of the IB_Dataset to hide fields that you
don't want show in multi-column controls. This property applies to all
multi-column controls bound to that dataset. Hint: you can access the
FieldsXXX properties at design-time, in the dataset editor, by
double-clicking on the IB_Query object.


>Oh, and btw: I couldn't get anything to display in the IB_Listbox, by just
>filling in the Datasource and DataField properties. Is there something else
>I need to do with it?

Yes: you have to populate the Items property of the control. :-) The
Datasource property binds the control to the dataset; DataField binds it
to the column that it will represent.

Items is a TStringList. You can add the items at design-time, in the Items
editor, or at run-time, e.g.

with IB_Listbox1.Items do
begin
Clear;
Add('Monday');
Add('Tuesday');
......
end;
or, write a procedure that uses a dataset (ideally an ib_cursor):

...
with IB_Cursor1, IBListbox1 do
begin
if not Prepared then Prepare; // prepares the cursor statement
Clear; // clears the stringlist
try
First; // fetches the first row of the dataset
while not EOF do
begin
Items.Add(FieldByName('aField').AsString);
Next;
end;
finally
Unprepare; // releases resources used by the ib_cursor
end;
end;

Some multi-row controls are "double data-aware" - such as TIB_LookupCombo
and TIB_LookupList. By "double-data-aware" means that the lookup part is
bound to one dataset whilst the value of the currently selected list item
is bound to the current record of another. The binding mechanism for these
controls is different; and they also have a GridLinks property that can
optionally be used to override, for that control only, the columns
determined by the dataset's FieldsVisible property.

Double-data-aware controls are another chapter. :-)

Helen