Add an item into only one combobox which is binded with a list bound to multiple ctrl

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sree078
    New Member
    • May 2007
    • 9

    Add an item into only one combobox which is binded with a list bound to multiple ctrl

    I've a list of items which I bound to multiple combo boxes.
    In the due course in the code...I had to add an item into one combo box...but I don't want it to be reflected into any other combo boxes...How should I do that...
    As when I'm trying to add an item...it is being shown in all the combo boxes.

    Code:
    private void FillMethod() 
    { 
               BindingSource bs = new BindingSource();
                BindingSource bs1 = new BindingSource();
                BindingSource bs2 = new BindingSource(); 
    
                List<string> list = Filldata();
                bs.DataSource = list;
                bs1.DataSource = list;
                bs2.DataSource = list; 
    
               comboBox1.DataSource = bs;
               comboBox2.DataSource = bs1; 
               comboBox3.DataSource = bs2;
    
              combobox1.items.add("sai");
    }
    Last edited by PRR; Apr 14 '09, 12:21 PM. Reason: Please post code in [code] [/code] tags.
  • Bassem
    Contributor
    • Dec 2008
    • 344

    #2
    Code:
    private void FillMethod() 
    { 
               bs.DataSource = list;
               comboBox1.DataSource = bs.Clone();
               comboBox2.DataSource = bs.Clone(); 
               comboBox3.DataSource = bs.Clone();
    
              combobox1.items.add("sai");
    }
    I tested none, but I'm sure that DataSource of each ComboBox now has a different copy of list.
    Last edited by Bassem; Apr 14 '09, 09:50 PM. Reason: modifying code tags

    Comment

    • sree078
      New Member
      • May 2007
      • 9

      #3
      We don't have Clone method in binding source.

      My requirement is adding one item in only one combo box and it should not reflect in our combo boxes...

      Comment

      • Bassem
        Contributor
        • Dec 2008
        • 344

        #4
        OK.
        You may do this.
        Code:
        private void FillMethod() 
        { 
                   comboBox1.DataSource = list.Clone();
                   comboBox2.DataSource = list.Clone(); 
                   comboBox3.DataSource = list.Clone();
        
                  combobox1.items.add("sai");
        }
        It's not about Clone Method. To not affect on the other DataSource they've to be different.

        Comment

        • tlhintoq
          Recognized Expert Specialist
          • Mar 2008
          • 3532

          #5
          I've a list of items which I bound to multiple combo boxes.
          In the due course in the code...I had to add an item into one combo box...but I don't want it to be reflected into any other combo boxes...How should I do that...
          As when I'm trying to add an item...it is being shown in all the combo boxes.
          As it would be. Same source equals same result. If you want different result then you need a different source.

          Walk it through in your mind for a moment... How can you envision a way to tell the computer to filter a single list so that some items are in combobox1 and others in combobox3? All items that start with the letter 'g'? Only items 1,4,8?

          Whatever criteria you can devise for the filtering would have to be done first... get those results... then add those results to the Combobox.Items collection directly instead of trying to do it with binding.

          Comment

          Working...