const string DGVCBCellType = "System.Windows.Forms.DataGridViewComboBoxCell";
const string DGVTBCellType = "System.Windows.Forms.DataGridViewTextBoxCell";
public CDynIngDGV() //构造函数
{
this.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(CDynIngDGV_EditingControlShowing);
this.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter;
}
void CDynIngDGV_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
switch (e.Control.GetType().ToString())
{
case DGVCBCellType:
((ComboBox)e.Control).SelectedValueChanged += new EventHandler(CDynIngDGV_SelectedValueChanged);
break;
case DGVTBCellType:
break;
}
}
void CDynIngDGV_SelectedValueChanged(object sender, EventArgs e)
{
switch (sender.GetType().ToString())
{
case DGVCBCellType:
MessageBox.Show(((ComboBox)sender).SelectedValue.ToString());
break;
case DGVTBCellType:
break;
}
}