ComboBox hell

ComboBox hell

Old forum URL: forums.lhotka.net/forums/t/2900.aspx


ajj3085 posted on Friday, May 18, 2007

Hi,

I have a couple of comboboxes which I want to bind to properties on my BO.  The first is a company combo box.  The user may select an item from the list (and AutoComplete is on) or may type something not in the list.  The BO property is simply a string. 

My first problem is how to bind this properly?  If the user types a property, SelectionIndexChanged doesn't fire, and the BO isn't updated if I bind the BO property to the SelectedValue.  To handle this, I'm also binding the Text property to the same BO property.  I'm not sure if thats the best way to handle this or not..

I also have a department text box which works the same way.  The difference is that its datasource depends on if a value is selected from the Company combo box, so that only departments belonging to the selected company are shown (or the list should be cleared if the user typed something not in the company combo's selection list).  I have the same bindings on this combo box as well.  The problem is that when the company selection changes, I update the department combos datasource and set SelectedIndex to -1 (otherwise the combo selects the first item in the list).  For some reason, the Text is being set to -1.  

Any ideas?  I know someone has done something similar before.

DansDreams replied on Friday, May 18, 2007

Did you try it just binding the Text property of the control?  I would think the key would be finding something that changes whether it's from typing or selecting, and that would be my first guess.

ajj3085 replied on Friday, May 18, 2007

Yes, and it works fine for the company text box, but not for the Department text box. 

Oddly, even setting the Text property on the Department combobox doesn't cause that value to be pushed into the BO..

I did find where the -1 was coming from; the form is old, and I had code to change the binding so that null was changed to -1. 

Copyright (c) Marimer LLC