Box文本当DatagridviewComboBox选择的指数变

Box文本当DatagridviewComboBox选择的指数变

本文介绍了更改DatagridviewTextBox文本当DatagridviewComboBox选择的指数变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In My DatagridView,I Have Two Columns, ComboxboxColumn and TextboxColumn. I want to change the value of textboxwhen 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();
    }



这篇关于更改DatagridviewTextBox文本当DatagridviewComboBox选择的指数变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 01:10