日期:2014-05-18  浏览次数:21518 次

datagridview 怎么获取选中行的某一列的索引
比如 下面是表
学号 姓名 所在年级
 1 张 高一
 2 李 高二
当我选择第二行的时候 我想取所在年级的列索引 这时候那个列索引应该是3 我怎么取得呢 谢谢大家

------解决方案--------------------
假如那列的name是 xxx,
dataGridView1.CurrentRow.Cells["xxx"].ColumnIndex
------解决方案--------------------
DataGridViewRow row = this.dataGridView1.CurrentRow;//当前行
object value = row.Cells[列索引或列名];
------解决方案--------------------
当前行指定列的索引
dataGridView1.CurrentRow.Cells["所在年级"].ColumnIndex // 3

当前行索引
dataGridView1.CurrentRow.Index // 1 (第二行)

当前单元格的列索引
dataGridView1.CurrentCell.ColumnIndex

当前单元格的行索引
dataGridView1.CurrentCell.RowIndex