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

解决方案 »

  1.   

    假如那列的name是 xxx,
    dataGridView1.CurrentRow.Cells["xxx"].ColumnIndex
      

  2.   

    DataGridViewRow row = this.dataGridView1.CurrentRow;//当前行
    object value = row.Cells[列索引或列名];
      

  3.   

    当前行指定列的索引
    dataGridView1.CurrentRow.Cells["所在年级"].ColumnIndex  // 3当前行索引
    dataGridView1.CurrentRow.Index  // 1 (第二行)当前单元格的列索引
    dataGridView1.CurrentCell.ColumnIndex当前单元格的行索引
    dataGridView1.CurrentCell.RowIndex