比如说,我的DataGridView表格如下:
学号      姓名         成绩现在我选了“学号”下的一个单元格,那么我怎么样才能读出我所选的这行数据中的姓名和成绩信息呢?

解决方案 »

  1.   

    try...string name = dataGridView1.CurrentRow.Cells["name"].Value;
    string score = dataGridView1.CurrentRow.Cells["score"].Value;
      

  2.   

    private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) 
            { 
                if (e.ColumnIndex ==姓名.Index) 
                { 
                    string s=dataGridView1[姓名.Index, e.RowIndex].Value; 
                } 
            }    
      

  3.   

    设置属性:
    this.dataGridView1.MultiSelect = false;
                this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;然后:
                DataGridViewRow row = this.dataGridView1.CurrentRow;
                string score = row.Cells["成绩"].Value==null?string.Empty:row.Cells["成绩"].Value.ToString();
                string name=row.Cells["姓名"].Value==null?string.Empty:row.Cells["姓名"].Value.ToString();