Hi Barbi
I have written an example for you to implement this.
Code Snippet
public partial class Form1 : Form
private DataSet ds1 = new DataSet();
private DataSet ds2 = new DataSet();
private DataTable dtSource = new DataTable("dtSource");
private DataTable dtComboBox = new DataTable("dtComboBox");
private ComboBox cmb;
public Form1()
"Value");
"Name");
"Item1");
"Item2");
"Item3");
"Item4");
"Column1");
"Column2");
"test1");
"test2");
"test3");
"test4");
DataGridViewComboBoxColumn dgvComboBox = new DataGridViewComboBoxColumn();
"Name";
"Column1_Name";
"Value";
"Column1";
"dtComboBox"];
"dtSource";
DataGridViewTextBoxColumn dgvText = new DataGridViewTextBoxColumn();
"Column1_Value";
new DataGridViewCellFormattingEventHandler(dataGridView1_CellFormatting);
new DataGridViewEditingControlShowingEventHandler(dataGridView1_EditingControlShowing);
void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
if (e.RowIndex < dtSource.Rows.Count)
void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
as ComboBox;
if (cmb != null)
new EventHandler(cmb_SelectedValueChanged);
void cmb_SelectedValueChanged(object sender, EventArgs e)
this.dataGridView1[0, dataGridView1.CurrentRow.Index].Value = cmb.SelectedValue;
The CellFormatting event of the DataGridView allow you to fill the Column1_Value at the first run. Then you can handle the EditingControlShowing event of the DataGridView to set the first column(Column_Value) cell value according to the ComboBox select action.
Sincerely,
Kira Qian
Windows Forms General FAQs Windows Forms Data Controls and Databinding FAQs |