I have a form that has two combo boxes, both of which contain the same list of items, and need to remain perfectly in sync with one another. (They represent the same list of options on two different tabs of a TPageControl
.)
To make this work, I set up a LiveBinding to bind both controls to the same field of a ClientDataset that exists for no other purpose than to keep controls on this form synchronized. My TBindingsList
has a TLinkControlToField
for both combo boxes, linking them both to the same field.
Everything works fine, as long as I make all changes within the GUI.
However, if an unrelated action changes the selection state of one of the boxes, they get out of sync:
cboMainValue.Items.InsertObject(0, 'ALL', TObject(-1));
cboAltValue.Items.Clear;
cboAltValue.Items.Assign(cboMainValue.Items);
cboMainValue.ItemIndex := 0;
cboAltValue.ItemIndex := 0;
After this point, for whatever reason, cboMainValue
shows the expected text, while cboAltValue
remains blank (ie ItemIndex = -1
).
I've tried setting the Text
property rather than ItemIndex
, and editing the value of the backing field on the ClientDataset, but none of these produces a different result.
Does anyone know how to programmatically change the state of one combo box and make the LiveBindings update the other one to match it?
parent
in theTPageControl.OnChange
event. The need to sync would not exist anymore. – Tom Brunberg