Subject | IB_LookupCombo.TextWidth |
---|---|
Author | Markus Ostenried |
Post date | 2001-08-19T15:59:40Z |
Hi all,
I have an Array of dynamically created LookupCombos. The LookupDataset
of each LookupCombo depends on the current record of the previous
LookupCombo.
I want to display the Combos next to each other. To avoid unnecessary
space between the Combos I need to calculate the Width (in Pixels) of
the Text displayed in the Combos.
I tried somtheing like this:
var
FComboCanvas: TControlCanvas;
sText: String;
tw: Integer;
begin
FComboCanvas := TControlCanvas.Create;
try
FComboCanvas.Control := FLCNode {the ComboBox};
sText := FQryLkNode.FieldByName( 'TN_TEXT' ).AsString;
tw := FComboCanvas.TextWidth( sText ) + 4;
FLCNode.Width := Max( 20, tw );
finally
FComboCanvas.Free;
end;
end;
But this gives me the wrong result. Does anyone know how to get
the exact width ?
My second problem is to find an event when to adjust the width.
I tried ComboBox.OnCloseUp but when this event occurs then
sometimes
FQryLkNode.FieldByName('TNR_ID_NODEREL').IsNull = true;
I guess that during this event the Dataset is scrolling and therefor
has no current record. "AfterScroll" fires too often.
Is there a better event for this ?
Note: The Lookup-Datasets of the Combos have no KeySources because
I need to write the selected record-keys manually into a table because
the structure of the Data is TreeView-like.
Many TIA,
Markus
I have an Array of dynamically created LookupCombos. The LookupDataset
of each LookupCombo depends on the current record of the previous
LookupCombo.
I want to display the Combos next to each other. To avoid unnecessary
space between the Combos I need to calculate the Width (in Pixels) of
the Text displayed in the Combos.
I tried somtheing like this:
var
FComboCanvas: TControlCanvas;
sText: String;
tw: Integer;
begin
FComboCanvas := TControlCanvas.Create;
try
FComboCanvas.Control := FLCNode {the ComboBox};
sText := FQryLkNode.FieldByName( 'TN_TEXT' ).AsString;
tw := FComboCanvas.TextWidth( sText ) + 4;
FLCNode.Width := Max( 20, tw );
finally
FComboCanvas.Free;
end;
end;
But this gives me the wrong result. Does anyone know how to get
the exact width ?
My second problem is to find an event when to adjust the width.
I tried ComboBox.OnCloseUp but when this event occurs then
sometimes
FQryLkNode.FieldByName('TNR_ID_NODEREL').IsNull = true;
I guess that during this event the Dataset is scrolling and therefor
has no current record. "AfterScroll" fires too often.
Is there a better event for this ?
Note: The Lookup-Datasets of the Combos have no KeySources because
I need to write the selected record-keys manually into a table because
the structure of the Data is TreeView-like.
Many TIA,
Markus