Binding 2 sets of combo boxes

Mar 19 2018 5:29 PM
i am trying to bind 2 sets of combo boxes to input into a database, the first set will work if i delete the second set , but i cannot get both to work at the same time. Please Help.
private void Form1_Load(object sender, EventArgs e)
{
System.Data.DataTable dt = new System.Data.DataTable();

System.Data.DataColumn dc1 = new System.Data.DataColumn("AccountName");
System.Data.DataColumn dc2 = new System.Data.DataColumn("AccountNumber");

dt.Columns.Add(dc1);
dt.Columns.Add(dc2);


dt.Rows.Add("Cash", "0100");
dt.Rows.Add("Accounts Recievable", "0200");
dt.Rows.Add("Account Payable", "0300");
dt.Rows.Add("Equipment", "0400");
dt.Rows.Add("Supplies", "0500");
dt.Rows.Add("Notes Payable", "0600");
dt.Rows.Add("Service Revenue", "0700");
dt.Rows.Add("Wages Expense", "0800");
dt.Rows.Add("Utilities", "0900");
dt.Rows.Add("Unearned Income", "1000");


AccountNamecomboBox1.DataSource = dt;

AccountNamecomboBox1.DisplayMember = "AccountName";
AccountNamecomboBox1.ValueMember = "AccountNumber";


AccountNumbercomboBox1.DataSource = dt;

AccountNumbercomboBox1.DisplayMember = "AccountNumber";
AccountNumbercomboBox1.ValueMember = "AccountName";

System.Data.DataTable dt1 = new System.Data.DataTable();

System.Data.DataColumn dc3 = new System.Data.DataColumn("AccountName1");
System.Data.DataColumn dc4 = new System.Data.DataColumn("AccountNumber1");

dt1.Columns.Add(dc3);
dt1.Columns.Add(dc4);


dt1.Rows.Add("Cash", "0100");
dt1.Rows.Add("Accounts Recievable", "0200");
dt1.Rows.Add("Account Payable", "0300");
dt1.Rows.Add("Equipment", "0400");
dt1.Rows.Add("Supplies", "0500");
dt1.Rows.Add("Notes Payable", "0600");
dt1.Rows.Add("Service Revenue", "0700");
dt1.Rows.Add("Wages Expense", "0800");
dt1.Rows.Add("Utilities", "0900");
dt1.Rows.Add("Unearned Income", "1000");

AccountNamecomboBox2.DataSource = dt1;

AccountNamecomboBox2.DisplayMember = "AccountName1";
AccountNamecomboBox2.ValueMember = "AccountNumber1";

AccountNumbercomboBox2.DataSource = dt1;

AccountNumbercomboBox2.DisplayMember = "AccountNumber1";
AccountNumbercomboBox2.ValueMember = "AccountName1";

Answers (2)