Click here to Skip to main content
15,895,256 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Iam Creating The ComboBox Dynamically Based on input . When i select first ComboBox value
rest of The all ComboBox also changed .

Iam Adding Controls Dynamically

C#
cmbSource = new ComboBox[dtExelData.Columns.Count];
               cmbDestination = new ComboBox[dtExelData.Columns.Count];
               for (int i = 0; i <= dtExelData.Columns.Count - 1; i++)
               {
                   cmbSource[i] = new ComboBox();
                   cmbSource[i].Name = Convert.ToString("cmbSource" + i);
                   cmbSource[i].Location = new Point(100, x);
                   this.Controls.Add(cmbSource[i]);
                   cmbSource[i].DataSource = lHeader;

                   // MessageBox.Show(cmbSource[i].Name.ToString());

                   cmbDestination[i] = new ComboBox();
                   cmbDestination[i].Name = Convert.ToString("cmbDest" + i);
                   cmbDestination[i].Location = new Point(400, x);
                   this.Controls.Add(cmbDestination[i]);
                   cmbDestination[i].DataSource = dsTblColumns.Tables[0];
                   cmbDestination[i].DisplayMember = "column_name";
                   cmbDestination[i].ValueMember = "column_name";
                   x = x + 40;
               }



Please let me know how solve this ?
Posted
Updated 24-Jul-13 22:57pm
v3
Comments
Pheonyx 25-Jul-13 4:05am    
is this a windows forms app? a WPF app? a metro app?
How are you creating the combo boxes?
please use the Improve question feature to add concise code snippets were appropriate.
Rambabu Sapa 25-Jul-13 4:56am    
Iam adding Controls Dynamically Which is shown below
cmbSource = new ComboBox[dtExelData.Columns.Count];
cmbDestination = new ComboBox[dtExelData.Columns.Count];
for (int i = 0; i <= dtExelData.Columns.Count - 1; i++)
{
cmbSource[i] = new ComboBox();
cmbSource[i].Name = Convert.ToString("cmbSource" + i);
cmbSource[i].Location = new Point(100, x);
this.Controls.Add(cmbSource[i]);
cmbSource[i].DataSource = lHeader;

// MessageBox.Show(cmbSource[i].Name.ToString());

cmbDestination[i] = new ComboBox();
cmbDestination[i].Name = Convert.ToString("cmbDest" + i);
cmbDestination[i].Location = new Point(400, x);
this.Controls.Add(cmbDestination[i]);
cmbDestination[i].DataSource = dsTblColumns.Tables[0];
cmbDestination[i].DisplayMember = "column_name";
cmbDestination[i].ValueMember = "column_name";
x = x + 40;
}
Pheonyx 25-Jul-13 5:01am    
Is there a property called "IsSynchronizedWithCurrentItem" if so, then I believe you need to set it to false.

You've not said what type of application this is either (at least not that I could see).

this is because your all comboboxs use same datasoruce .

for every combobox you must have a datasoruce .


best regrads
 
Share this answer
 
To Resovle This Problem we have Copy The Datset into New Dataset And Bind The combobox with new dataset


cmbSource = new ComboBox[dtExelData.Columns.Count];
cmbDestination = new ComboBox[dtExelData.Columns.Count];
for (int i = 0; i <= dtExelData.Columns.Count - 1; i++)
{
cmbSource[i] = new ComboBox();
cmbSource[i].Name = Convert.ToString("cmbSource" + i);
cmbSource[i].Location = new Point(70, x);
PanelControls.Controls.Add(cmbSource[i]);
DataTable newheaderdata = new DataTable(i.ToString());
newheaderdata = dsHeader.Tables[0].Copy();

cmbSource[i].DataSource = newheaderdata;
cmbSource[i].DisplayMember = "name";
cmbSource[i].ValueMember = "name";
// MessageBox.Show(cmbSource[i].Name.ToString());
cmbDestination[i] = new ComboBox();
cmbDestination[i].Name = Convert.ToString("cmbDest" + i);
cmbDestination[i].Location = new Point(300, x);
PanelControls.Controls.Add(cmbDestination[i]);

DataTable newData = new DataTable(i.ToString());
newData = dsTblColumns.Tables[0].Copy();

cmbDestination[i].DataSource = newData;
cmbDestination[i].DisplayMember = "name";
cmbDestination[i].ValueMember = "name";

x = x + 40;
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900