更改DatagridviewTextBox文本当DatagridviewComboBox选择的指数变化文本、指数、DatagridviewTextBox、DatagridviewComboBox

由网友(~爱过了_也伤透了℡)分享简介:在我的的DataGridView ,我有两列, ComboxboxColumn 和 TextboxColumn 。我想改变文本框的值在组合框中选择指数的变化(一般组合框中已经选择指数的变化情况,但 datagridviewComboBox 没有它)In My DatagridView,I Have Two Colu...

在我的的DataGridView ,我有两列, ComboxboxColumn TextboxColumn 。我想改变文本框的值 在组合框中选择指数的变化(一般组合框中已经选择指数的变化情况,但 datagridviewComboBox 没有它)

In My DatagridView,I Have Two Columns, ComboxboxColumn and TextboxColumn. I want to change the value of textbox when combobox selected index changes (in general combobox it has selected index change event but datagridviewComboBox does not have it)

推荐答案

给这两个简单的方法去(在上面方法的'1'是ComboBox列的索引)

Give these two simple methods a go (the '1' in the top method is the index of the combobox column)

这是你让你修改的线路将是二传手行 cel.Value = ,你可以将其更改为任何你喜欢的。

The line that you would make you modifications to would be the setter line cel.Value =, as you may change it to whatever you like.

    private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
    {
        if (dataGridView1.CurrentCell.ColumnIndex == 1 && e.Control is ComboBox)
        {
            ComboBox comboBox = e.Control as ComboBox;
            comboBox.SelectedIndexChanged += LastColumnComboSelectionChanged;
        }
    }

    private void LastColumnComboSelectionChanged(object sender, EventArgs e)
    {
        var currentcell = dataGridView1.CurrentCellAddress;
        var sendingCB = sender as DataGridViewComboBoxEditingControl;
        DataGridViewTextBoxCell cel = (DataGridViewTextBoxCell)dataGridView1.Rows[currentcell.Y].Cells[0];
        cel.Value = sendingCB.EditingControlFormattedValue.ToString();
    }

阅读全文

相关推荐

最新文章