DataGridView下拉列表联动

找的时候费了很大的劲,特别记录一下

private void dgvServiceItem_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
DataGridView dgvTemp = (DataGridView)sender;
if (dgvTemp.CurrentCell.RowIndex != -1 && dgvTemp.CurrentCell.ColumnIndex == 1)
{
((ComboBox)e.Control).SelectedIndexChanged += new EventHandler(FrmAddPackage_SelectedIndexChanged);
}
}

private void FrmAddPackage_SelectedIndexChanged(object sender, EventArgs e)
{
ComboBox cbTemp = (ComboBox)sender;
cbTemp.SelectedIndexChanged -= new EventHandler(FrmAddPackage_SelectedIndexChanged);
}


这种方式绑定数据源的时候有问题

你可能感兴趣的:(datagridview)