引用來源
---------------------------------------
namespace C_Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
ComboBox cbo = new ComboBox();
private void Form1_Load(object sender, EventArgs e)
{
DataGridView GridView = new DataGridView();
GridView.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(this.GridView_EditingControlShowing);
this.Controls.Add(GridView);
DataGridViewComboBoxColumn comboBoxColumn = new DataGridViewComboBoxColumn();
comboBoxColumn.Items.AddRange(1, 2, 3, 4);
comboBoxColumn.ValueType = typeof(Int32);
GridView.Columns.Add(comboBoxColumn);
}
private void GridView_EditingControlShowing(Object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (e.Control.GetType().Name == "DataGridViewComboBoxEditingControl")
{
cbo = (ComboBox)e.Control;
cbo.SelectedIndexChanged += new System.EventHandler(this.cbo_SelectedIndexChanged);
}
}
private void cbo_SelectedIndexChanged(Object sender, EventArgs e)
{
MessageBox.Show(cbo.Text);
}
}
}
沒有留言:
張貼留言