- Category: Visual Basic.Net
- Published on Monday, 02 February 2009 16:10
- Written by Shabdar
- Hits: 11843
Based on my understanding, what Sheng Jiang has advised is practical. DataGridViewComboBoxColumn can work perfectly as you like.
I would like to suggest you write code like following:
1. Initialize two BindingSources, and bind them separately to Designation_Master and Employee_Master
connection = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=E:\\temp\\MyDatabaseData2.MDF;Integrated " +
"Security=True;Connect Timeout=30;User Instance=True");
// Initialization on table1.
command1 = new SqlCommand("select Employee_Designation from Designation_Master;", connection);
dataAdapter1 = new SqlDataAdapter();
bindingSource1 = new BindingSource();
dataAdapter1.SelectCommand = command1;
bindingSource1.DataSource = Desination_Table;
// Initialization on table2.
command2 = new SqlCommand("select Employee_Name from Employee_Master;", connection);
dataAdapter2 = new SqlDataAdapter();
bindingSource2 = new BindingSource();
dataAdapter2.SelectCommand = command2;
bindingSource2.DataSource = Employee_Table;
2. Bind two ComboBoxColumn separately to these two BindingSources.
Code Snippet this.Column1.DataSource = bindingSource1;
this.Column1.DisplayMember = "Employee_Designation";
this.Column2.DataSource = bindingSource2;
this.Column2.DisplayMember = "Employee_Name";
3. Implement DataGridView.EditingControlShowing event, in order to make lists of values up to date.
Code Snippet private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)