I know, winforms is an outdated technology, but I've got to struggle with it.
My object is presented on a form with one of it's props beeing shown through a combobox. So far so good. When showing already db-persisted objects, all goes fine and it shows the correct values (quite not until I first bound the object and then the combobox's list, of course).
Trouble starts, when I create a new object. While there is a value choosen in the box, the objects property remains empty
What do I have to do to REALLY bind the property?
Thanks for your time
I think you have to do it the other way around; bind the ComboBox's list items first, then bind your business object.
If you drag a combox from the datasources windows the WinForms designer will create a databinding on the Text property. But that's usually not what you want to do with a BO property and using a NameValueList of valid choises.
I'd recommend to drag a ComboBox from from the Toolbox and then use the ComboBox Tasks to configure databinding.And - then make sure to set the combobox listsource before you set the datasource for your BO and make sure to unbind in the opposite order.
Finally - download the DataBinding FAQ, DataGridView FAQ and Designer FAQ from http://www.windowsclient.net. These FAQ are essential if you are going to be successful with Windows Forms Databinding. I also recommend to use the Windows Forms FAQ on the same site.
One more detail, usually the BO property gets bound to the combo's .Value, not the .Text. There are exceptions, but typically the Value is saved to the BO and db, not the human readable Name.
thank you for your input. I've got to admit that I feel somehow sheepish about the real reason: the combobox is the last control in tab order and pressing 'save' just after choosing a value demands some form-validation, otherwise you'll see a selected value, but it isn't really written to the datasource
So my $/€ into the kitty...
This is a recurring question as PTracker doesn't include an example of combobox binding. Does anyone have a small sample to post?
Copyright (c) Marimer LLC