dataGridViewではフォーカスが移った際、
SelectionChangedイベントが実行されます。
その中で、2列目か判断してあげてください。
なお、選択されているセル(or 列 or 行)を取得するのは以下のページを参考にしてください。
http://dobon.net/vb/dotnet/datagridview/selectedcells.html
・セルの取得
lang
1foreach (DataGridViewCell c in DataGridView1.SelectedCells)
2{
3 Console.WriteLine("{0}, {1}", c.ColumnIndex, c.RowIndex);
4}
・行を表示
lang
1Console.WriteLine("選択されている行");
2foreach (DataGridViewRow r in DataGridView1.SelectedRows)
3{
4 Console.WriteLine(r.Index);
5}
・列を表示
lang
1Console.WriteLine("選択されている列");
2foreach (DataGridViewColumn c in DataGridView1.SelectedColumns)
3{
4 Console.WriteLine(c.Index);
5}
■例を記載しておきます。
lang
1private void dataGridView1_SelectionChanged(object sender, EventArgs e)
2{
3 foreach (DataGridViewCell c in dataGridView1.SelectedCells)
4 {
5 Console.WriteLine("{0}, {1}", c.ColumnIndex, c.RowIndex);
6
7 if(c.ColumnIndex == 1)
8 {
9 Console.WriteLine("2列目です");
10 }
11 }
12}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/01/27 00:15