Combobox with Dynamic NVL

Combobox with Dynamic NVL

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


Vinodonly posted on Monday, July 02, 2007

I searched the forum but was not able to find reply for this issue so posting it here. I have cached data and with that cached data i'm creating NameValueList object and filling it on the fly.

Something like this :-

Dim ValueList As New NVList

Then adding the values from the cached data using ValueList.Add

I'm setting following values in my targeted combo box

MyComboBox.DataSource = Nothing

MyComboBox.DataSource = ValueList

MyComboBox.DisplayMember = "Value"

MyComboBox.ValueMember = "Key"

Problem is that at initial form load values are getting filled up but when i make changes in ValueList and refill the Combobox with code mentioned above then combo box becomes empty.

Pls note I have no binding source and i don't want to use binding source. Reason is that there are lot of comboboxes and i want to handle this all through code without using bindingsource.

can anybody help me on this..

JonM replied on Monday, July 02, 2007

I've also seen some weird issues with combobox binding, try the following tips.

1.  Make sure the datasource is tied to 1 combobox only, when tied to more than 1 unpredicatable things happen.

2.  If you are repopulating the box make sure you have cleared the databindings and set the datasource to null first.  (This is also a good thing to do with the datagridview).

3.  For some reason I've occasionally had issues running databinding code from a form's constructor.  I've had better luck calling from the 'Activated' event.

Good Luck.

Vinodonly replied on Monday, July 02, 2007

Thanks a lot for your reply and tips.

Kindly note that i'm creating dynamic NVL's for each combobox, so datasource is different for all the comboboxes.

I will test out all the tips and post the final outcome.

Thanks for your help.

 

JonM replied on Monday, July 02, 2007

Okay, I understand.  I recently had to tackle an issue like this.  Basically, I had a grid with 2 columns.  I wanted the list of items in the second column to get different based on what was selected in the first column.  It took me a way from the auto databinding for the most part and forced me to hook to the events in the various datagridview columns.

Copyright (c) Marimer LLC