|
|
Problem with ComboBox DataBinding to ROLB
Last post 12-22-2008, 1:53 PM by ajj3085. 4 replies.
-
12-22-2008, 11:09 AM |
-
lukky
-
-
-
Joined on 05-29-2006
-
Sherbrooke, Qc, Canada
-
Posts 85
-
Points 1,415
-
|
Problem with ComboBox DataBinding to ROLB
Hi,
I have CustomerInfo and CustomerInfoList classes deriving from ReadOnlyBase and ReadOnlyListBase.
On a Windows Form, I create a BindingSource, and set its DataSource to the CustomerInfo class (I have previously added the CustomerInfo class as a DataSource).
Then I set the ComboBox DataSource to the BindingSource, set the DisplayMember to CustName, and the ValueMember to CustId.
Finally, I set the ComboBox DataBinding SelectedValue to point to the yet another BindingSource that tracks the currently selected Invoice (BusinessBase derived).
This is a typical ComboBox databinding scenario, but for some reason it doesn't work as expected.
When I select a CustName from the ComboBox, the CustId doesn't get pushed to the Invoice.
So I set a temporary event handler on the SelectedIndexChanged to examine the currently selected CustomerInfo. I assume that since I have set the ValueMember of my ComboBox to CustId, whenever the ComboBox_SelectedIndexChanged event is raised, the ComboBox.SelectedValue should be the CustId. But I'm seeing the actual CustomerInfo object. This seems to prevent the DataBinding mechanism to work, as it is expecting an Integer (CustId), not a CustomerInfo.
Am I missing something basic here ? Should this scenario work as described ?
Thank you.
Luc Morin, T.P. http://www.stlm.ca
|
|
-
12-22-2008, 11:36 AM |
-
ajj3085
-
-
-
Joined on 05-05-2006
-
Vermont
-
Posts 3,177
-
Points 48,375
-
|
Re: Problem with ComboBox DataBinding to ROLB
I think you'll want your BindingSource.DataSource to be set to the CustomerInfoList class.
|
|
-
12-22-2008, 12:16 PM |
-
lukky
-
-
-
Joined on 05-29-2006
-
Sherbrooke, Qc, Canada
-
Posts 85
-
Points 1,415
-
|
Re: Problem with ComboBox DataBinding to ROLB
Hi,
Actually, at runtime, this is what I do. But, at design time, in order for the Visual Studio design time data binding stuff to work, one has to set the BindingSource's DataSource to the "Type" of objects that will be exposed by the BindingSource, so in my case, that's the CustomerInfo class. This allows me to select the ValueMember and DisplayMember for the ComboBox.
Then at runtime, I obtain a list of CustomerInfo object by calling the factory method CustomerInfoList.GetList(), then I set the BindingSource's DataSource property to the list.
Regards.
Luc Morin, T.P. http://www.stlm.ca
|
|
-
12-22-2008, 1:27 PM |
-
lukky
-
-
-
Joined on 05-29-2006
-
Sherbrooke, Qc, Canada
-
Posts 85
-
Points 1,415
-
|
Re: Problem with ComboBox DataBinding to ROLB
Hi again,
Actually, I have tried setting the BindingSource's DataSource at design time to the CustomerInfoList, and what have you, it works....
I had always used List<T> before, and it would work by setting the BindingSource's DataSource to the type within the List<T>. But with ROLB/ROB, things seem to be different, and one has to use ROLB at design time. I'd like to understand the difference in behavior.
Now, I do have another issue.
Normally, when you set the DataSourceUpdateMode to OnPropertyChanged, the value is pushed as soon as the user selects an entry in the ComboBox. At least this is what I see when I use List<T>. Using ROLB, the user needs to tab off the ComboBox in order for the value to be pushed. I have added a handler to the Binding.Format event, and it fires only after user tabs off.
Strange. Any one can shed some light on this ?
Thanks again.
Luc Morin, T.P. http://www.stlm.ca
|
|
-
12-22-2008, 1:53 PM |
-
ajj3085
-
-
-
Joined on 05-05-2006
-
Vermont
-
Posts 3,177
-
Points 48,375
-
|
Re: Problem with ComboBox DataBinding to ROLB
I think that when the BindingSource's Type changes, it loses other settings as well, which could be why you were getting the "strange" behavior.
I would double check the update mode on the combos' Value property; again it's possible it "forgot" it's setting when you changed the BindingSource in design time.
|
|
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. Why donate?
|
|
|