日期:2014-05-17  浏览次数:20931 次

求各位大哥帮忙我这个没货的专科生“如何给datagridview里面的combobox写事件”

比如图片的的combobox控件,我要实现的功能是下拉菜单,然后隔壁的textbox显示相应的编号和单价
------最佳解决方案--------------------

private void dataGridView1_EditingControlShowing(objectsender,DataGridViewEditingControlShowingEventArgs e)
        {
            if (dataGridView1.CurrentCell.RowIndex != -1 &&dataGridView1.CurrentCell.ColumnIndex == 0)
            {
                 //还原当前控件并绑定事件       
                ((ComboBox)e.Control).SelectedIndexChanged += new EventHandler(Form1_SelectedIndexChanged);
            }
        }
        //事件名自己定义
        private void Form1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //事件代码
            MessageBox.Show(((ComboBox)sender).SelectedIndex.ToString());
        }

------其他解决方案--------------------
引用:
引用:引用:引用:C# code?1234567891011121314private void dataGridView1_EditingControlShowing(objectsender,DataGridViewEditingControlShowingE……

我22就这么显老么?
------其他解决方案--------------------
private DataGridView dataGridView1 = new DataGridView();

private void AddColorColumn()
{
    DataGridViewComboBoxColumn comboBoxColumn =
        new DataGridViewComboBoxColumn();
    comboBoxColumn.Items.AddRange(
        Color.Red, Color.Yellow, Color.Green, Color.Blue);
    comboBoxColumn.ValueType = typeof(Color);
    dataGridView1.Columns.Add(comboBoxColumn);
    dataGridView1.EditingControlShowing +=
        new DataGridViewEditingControlShowingEventHandler(
        dataGridView1_EditingControlShowing);
}

private void dataGridView1_EditingControlShowing(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_Selec