Решение этой проблемы
Мой полный код находится ниже
Форма модуля нагрузки
private void Form1_Load(object sender, EventArgs e)
{
BindingSource bs = new BindingSource();
bs.Add("001");
bs.Add("002");
bs.Add("003");
bs.Add("004");
bs.Add("005");
try
{
DataGridViewComboBoxColumn combo1 = new DataGridViewComboBoxColumn();
combo1.HeaderText = "DepartmentID";
combo1.DataSource = bs;
combo1.Width = 220;
dataGridView1.Columns.Add(combo1);
DataGridViewTextBoxColumn text1 = new DataGridViewTextBoxColumn();
text1.Width = 200;
text1.HeaderText="DEPARTMENTNAME";
text1.ReadOnly = true;
DataGridViewTextBoxCell txt = new DataGridViewTextBoxCell();
dataGridView1.Columns.Add(text1);
DataGridViewComboBoxColumn combo2 = new DataGridViewComboBoxColumn();
combo2.HeaderText = "Status";
combo2.Items.Add("Active");
combo2.Items.Add("InActive");
combo2.Width = 220;
dataGridView1.Columns.Add(combo2);
}
catch (Exception ex)
{
MessageBox.Show("combo error");
}
}
dataGridView1_EditingControlShowing Модуль
private void dataGridView1_EditingControlShowing_1(object sender, DataGridViewEditingControlShowingEventArgs e)
{
ComboBox combo = e.Control as ComboBox;
if (combo != null)
{
// Remove an existing event-handler, if present, to avoid
// adding multiple handlers when the editing control is reused.
combo.SelectedIndexChanged -= new EventHandler(ComboBox_SelectedIndexChanged);
// Add the event handler.
combo.SelectedIndexChanged += new EventHandler(ComboBox_SelectedIndexChanged);
}
}
ComboBox_SelectedIndexChanged Модуль
private void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
ComboBox cb = (ComboBox)sender;
string item = cb.Text;
int irow = dataGridView1.CurrentCell.RowIndex;
if (item != null)
{
if (dataGridView1.CurrentCell.ColumnIndex == 0) // This IF is used for handling first combobox event in gridview
{
dataGridView1.Rows[irow].Cells[1].Value = item; // cell index [1] represent DepartmentName
}
}
}
Выход
Click here to view Output
Спасибо за ваш ответ .. @Leprechaun –