0

単純なテキスト ファイルを出力するアプリケーションを作成しようとしています。これは、C# での私の最初のプロジェクトです。データ グリッド テーブルを作成しました。各行には基本的に 5 つのセルがあり、行はユーザー入力後に動的に追加されます。ユーザーは、5 つのセルのうち 2 つの値のみを変更できます。私の問題はここにあります.3番目のセルでは、ユーザーはセル3のコンボボックスから値を選択する必要があります.コンボボックスの値が選択された後、セル4と5の値が入力されます. しかし、私はそれを行うことができません。参考までに画像を添付します。アプリケーションイメージ

4

1 に答える 1

2

次のようなことを試すことができます:

//EditingControlShowing event handler for your dataGridView1
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e){
   ComboBox combo = e.Control as ComboBox;
   if(combo != null) combo.SelectedIndexChanged += GridComboSelectedIndexChanged;
}
private void GridComboSelectedIndexChanged(object sender, EventArgs e) {
   ComboBox combo = sender as ComboBox;
   //Your populating code here
   //you can access the selected index via combo.SelectedIndex
   //you can access the current row by dataGridView1.CurrentCell.OwningRow
   //then you can access to the cell 4 and cell 5 by dataGridView.CurrentCell.OwningRow.Cells[4] and dataGridView.CurrentCell.OwningRow.Cells[5]
}
于 2013-08-11T00:20:44.480 に答える