|
how-to-insert-combo-box-in-datagridview-cell-in-vbnet-2005 |
|
|
|
|
Written by Shabdar
|
|
Monday, 02 February 2009 11:10 |
|
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
Code Snippet
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;
dataAdapter1.Fill(Designation_Table);
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;
dataAdapter2.Fill(Employee_Table);
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)
{
bindingSource1.EndEdit();
bindingSource2.EndEdit();
bindingSource1.ResetBindings(false);
bindingSource2.ResetBindings(false);
}
|
|
Last Updated on Thursday, 05 February 2009 11:06 |