3

d DataGridView( dgvHardwareという名前)コントロールを備えた基本的なWinFormsアプリがあり、このコントロールにバインドされているのは次のコードです。

    private void dgvHardware_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
    {
        if (e.Control is ComboBox)
        {
            ((ComboBox)e.Control).SelectionChangeCommitted -= new EventHandler(cboDgvHardware_SelectionChanged);
            ((ComboBox)e.Control).SelectionChangeCommitted += new EventHandler(cboDgvHardware_SelectionChanged);
        }
    }

    private void cboDgvHardware_SelectionChanged(object sender, EventArgs e)
    {
        // string result is the selected text of the combo box
        // int row is the row index that the selected combo box lives
        string result = ((ComboBox)sender).SelectedItem.ToString();
        // int row = ????
    }

簡単に言うと、ComboBoxの選択に基づいて行内の他のセルを変更するには、イベントが発生している行を判別できる必要があります。2番目の関数の結果は、その価値に対して正しい値を返します。

これが不明な場合、または追加情報が必要な場合はお知らせください。

ありがとう、
アンドリュー

4

2 に答える 2

6

次のようにDataGridView.CurrentCellプロパティを使用します。

int row = dgvHardware.CurrentCell.RowIndex;
于 2011-07-15T04:46:32.963 に答える
1

行全体にアクセスできることに興味があり、他のセル値dgvHardware.CurrentRowを使用して別の列に移動したり変更したりできます。dgvHardware.CurrentRow.Cells[index or columnName]

于 2011-07-15T05:07:21.980 に答える