CSLA .NET

Vibrant discussion about CSLA .NET and using the framework to build great business applications.

Forum has moved

New location: CSLA .NET forum


CSLA .NET Resources:
  • CSLA .NET forum
  • CSLA .NET home page
  • Two BindingSources with the Same DataSource Type

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

    Not Ranked
    4 Posts
    shaselsc posted on Wed, Feb 9 2011 3:06 PM

    Hello,

    Two different combo boxes for a C# WinForms application that need to have a list of the same data. They need to be able to have different values at any given time, so they can't use the same BindingSource. I have a NameValueList business object that has an ID(Key) and Name(Value). I want to set the BindingSource to the same type of business object. When using the Visual Studio 2010 GUI to achieve this, the first one works correctly, but after adding the second and setting it to the NameValueList business object, I get a rather strange runtime error: "DataMember property 'Position' cannot be found on the DataSource." It happens on this line of code in the Designer code file for the form:

    ((System.ComponentModel.ISupportInitialize)(this.associateListBindingSource)).EndInit();

    Is there a way to get around this or am I going about this the wrong way?

    Thanks,
    Steve

    Answered (Verified) Verified Answer

    Top 10 Contributor
    4,106 Posts
    Answered (Verified) Andy replied on Sat, Feb 12 2011 1:34 PM
    Verified by shaselsc

    Ok, looks like for some reason you need a different binding source for each combobox, but you can reuse the same exactly list BO as their data sources.

    All Replies

    Top 10 Contributor
    4,106 Posts
    Andy replied on Thu, Feb 10 2011 5:42 PM

    The DataSource for each drop down should be the same binding source, which will be where you set the list data (the shared list).

    You then bind the SelectedItem (or SelectedValue) to the business object's property which is to be updated by the list when it changes.  You do this in the Propreties window for the dropdown and expand the (Data bindings) node.

    Not Ranked
    4 Posts

    Hi Andy,

    Thanks for the reply. I tried setting them all to the same binding source. When that happens, anytime you change one drop down, the other changes as well. In my case, I need them to be able to be different values. One of them is a search criteria, and the other is a property of the business object. The business object is the Associate and the property is the ID of the Spouse, who's also an associate. It turns out I even needed a third drop down box as the users wanted to be able to bring up Associates by their ID, which also had to be sorted differently. I ended up creating a sort function using LINQ, which required me to create separate instances of the list anyway, so I used those different instances to set my DataSources for my combo boxes and setting the DisplayMember and ValueMember manually. I'm not sure if that's the ideal solution, but I went ahead and went with that for now. I'd be open for a better solution if you had any ideas though.

    Thanks again,
    Steve

    Top 10 Contributor
    4,106 Posts
    Answered (Verified) Andy replied on Sat, Feb 12 2011 1:34 PM
    Verified by shaselsc

    Ok, looks like for some reason you need a different binding source for each combobox, but you can reuse the same exactly list BO as their data sources.

    Page 1 of 1 (4 items) | RSS

    Copyright (c) 2006-2014 Marimer LLC. All rights reserved.
    Email admin@lhotka.net for support.
    Powered by Community Server (Non-Commercial Edition), by Telligent Systems