活动期间DataGridViewComboBoxColumn的SelectedIndexChanged的触发活动期间、DataGridViewComboBoxColumn、SelectedIndexC

由网友(唯安)分享简介:我有的DataGridView 有两列。第一列是 TextBoxCol(DataGridViewTextBoxColumn),第二个是 ComboBoxCol(DataGridViewComboBoxColumn)。I have DataGridView with two columns. The first col...

我有的DataGridView 有两列。第一列是 TextBoxCol(DataGridViewTextBoxColumn),第二个是 ComboBoxCol(DataGridViewComboBoxColumn)

I have DataGridView with two columns. The first column is TextBoxCol(DataGridViewTextBoxColumn) and the Second one is ComboBoxCol(DataGridViewComboBoxColumn).

如何修改 TextBoxCol 的值时, ComboBoxCol 改变其选定的指标值? (这应该发生在选定的指数变化 ComboBoxCol 不离开柱,等之后 dataGridView_CellValueChanged

How can I change the value of TextBoxCol when ComboBoxCol changes its selected index value? (This should happen when selected index changed in ComboBoxCol. Not after leaving the column, like dataGridView_CellValueChanged)

我看过一个主题,几乎,我有,但我不明白的答案(这应该是在复选标记正确基地)同样的问题。这里的链接。 -Almost同一主题的

I have read one topic with almost the same problem that I am having but I dont understand the answer(which should be correct base on the check mark). Here's the link. -Almost same topic

推荐答案

给这两个简单的方法去(在上面方法的'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();
    }

阅读全文

相关推荐

最新文章