CSLA .NET

From Rockford Lhotka's Expert C# 2008 and VB 2008 Business Objects books

Winforms databinding prob with combobox and newly created object

rated by 0 users
Answered (Verified) This post has 1 verified answer | 5 Replies | 0 Followers

Top 500 Contributor
22 Posts
vschaak posted on Mon, Mar 8 2010 8:43 AM

Hi @all,

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 emptyAngry

What do I have to do to REALLY bind the property?

Thanks for your time

Volker

Answered (Verified) Verified Answer

Top 500 Contributor
22 Posts
Answered (Verified) vschaak replied on Wed, Mar 10 2010 12:21 PM
Verified by vschaak

Hi

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 datasourceEmbarrassed

So my $/€ into the kitty...

Best wishes

Volker

All Replies

Top 10 Contributor
3,694 Posts
Answered (Not Verified) Andy replied on Mon, Mar 8 2010 10:47 AM
Suggested by Andy

I think you have to do it the other way around; bind the ComboBox's list items first, then bind your business object. 

Top 25 Contributor
281 Posts

Hi,

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 FAQDataGridView 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.

 

Jonny Bekkum, Norway CslaContrib Coordinator
Top 200 Contributor
40 Posts

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.

Top 500 Contributor
22 Posts
Answered (Verified) vschaak replied on Wed, Mar 10 2010 12:21 PM
Verified by vschaak

Hi

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 datasourceEmbarrassed

So my $/€ into the kitty...

Best wishes

Volker

Top 25 Contributor
169 Posts
tiago replied on Wed, Mar 10 2010 12:26 PM

This is a recurring question as PTracker doesn't include an example of combobox binding. Does anyone have a small sample to post?

Tiago Freitas Leal

Page 1 of 1 (6 items) | RSS

Please contact Magenic for your .NET consulting
and CSLA .NET mentoring needs.
Please consider making a donation to help support the ongoing development of CSLA .NET.

Make donation through PayPal - it's fast, free and secure!
Why donate?
Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems