Doug Steele
dbdoug at gmail.com
Fri Oct 24 11:27:05 CDT 2008
Hello All: I'm currently working on a Windows CE application I am a little baffled at the behavior of a bound combo box. Setup: I have a Combobox bound to a BindingSource, with the DisplayMember a name and the DisplayValue an integer which is the PK of the underlying table. I want the user to select a name and then (later) I am going to add a new row to a different table using the name's key value along with other key values taken from other combo boxes. Behaviour: When a selection is made in the combobox, the new name selected shows up as expected. However when I look at the combobox.ValueSelected, it is the key of the FIRST row, not the key of the currently displayed row. When I look at the BindingSource.Position, it is zero. If I watch the combobox.SelectedIndexChanged event, it always fires twice. The first time it fires, the ValueSelected contains the key value of the newly selected item and the BindingSource.Position is zero. The second time it fires, the ValueSelected has reverted to the key of the first row, and the BindingSource.Position is the position of the newly selected item. It looks like I can grab the key value I need by saving it whenever the SelectedIndexChanged event fires with a zero BindingSource.Position, but that seems kind of kludgy, and I don't know if I can trust it. Surely the whole point of a bound combobox is to supply the value of the displayed item. Am I missing something here? Thanks, Doug Steele