combobox selectedvalue vs text question  
Author Message
steveareno





PostPosted: Windows Forms Data Controls and Databinding, combobox selectedvalue vs text question Top

Is there one method for getting a value in a comboxbox (DropDownStyle set to DropDown) regardless of whether the user entered or selected a value.  My combobox is initially populated with a datatable and has a Value and Display member.  Since a user can enter thier own value, it would not have a ValueMember, therefore SelectedValue fails.  It seems I may have to test the SelectedValue and the Text properties for both validation and saving the data.  I was hoping there would be an easier way.

Also, I just noticed that I may not be able to use the DataBinding properties from my bindingsource because if I bind using the SelectedValue, if the value isn't in the list then it doesn't show up.  If I use the Text, everything works but I can't leave the control, let alone close the form.  It seems to get hung.



Windows Forms22  
 
 
Wang Chi





PostPosted: Windows Forms Data Controls and Databinding, combobox selectedvalue vs text question Top

I think if you do not want to user to modify the text in combobox, you'd better change DropDownStyle to DropDownList, otherwise, check selectedvalue != null whenever this property is used.