2011-07-15 15 views
3

私はこのコントロールにバインドされた(dgvHardwareという名前)のDのDataGridViewその上に制御、との基本的なWinFormsのアプリケーションを持っているが、このコードです:のDataGridViewのComboBox EditingControlShowingイベント

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番目の関数の結果は、それが価値のある正しい値を返します。

これが不明な場合や追加情報が必要な場合はお知らせください。あなたが行全体にアセスし、あなたが使用して別の列に移動可能性が得られますdgvHardware.CurrentRowに興味がある

int row = dgvHardware.CurrentCell.RowIndex; 

答えて

6

は、このようなDataGridView.CurrentCell Propertyを使用しますdgvHardware.CurrentRow.Cells[index or columnName]と他のセルの値を変更します。

+0

ビンゴ!それは99%正確で、DataGridViewの名前はdgvHardwareなので、完全に正しい行は 'int row = dgvHardware.CurrentCell.RowIndex;' – Fuginator

+0

@Fuginator Opps、copy and pasteエラーです。訂正されました! –

1

おかげで、
アンドリュー

関連する問題