int i = this.father._dgv.SelectedRows[0].Index;我这样可以选中行没?怎么还是弹出错误:索引超出范围。必须为非负值并小于集合大小。
参数名: index

解决方案 »

  1.   

    有啊   我是想从选中的行里面数据赋值给显示出来:int i = this.father._dgv.SelectedRows[0].Index;
    this.tb1.Text = this.father._dgv.SelectedRows[i].Cells[0].Value.ToString();
    this.tb2.Text = this.father._dgv.SelectedRows[i].Cells[1].Value.ToString();
    this.tb3.Text = this.father._dgv.SelectedRows[i].Cells[2].Value.ToString();
      

  2.   

    DataRowView drv = dataGridView.SelectedRows[0].DataBoundItem as DataRowView;
    DataGridView1.CurrentRow.Index 获得包含当前单元格的行的索引 
    是否选择了行
      

  3.   

    用这个:DataGridView1.CurrentRow.Index
      

  4.   

    我选中那行有 3 个单元格我是想把选中行的每个单元格的值 分别 赋给 :this.tb1.Text, this.tb2.Text ,this.tb3.Text 就在这时出错了~~
      

  5.   

    this.tb1.Text = this.father._dgv.SelectedRows[0].Cells[0].Value.ToString(); 
    直接这样写不行吗?
      

  6.   


    嗯 这样可以  但是我想用  int i = this.father._dgv.SelectedRows[0].Index; 这句来获取行号~~然后再赋值 就不行了~~~
      

  7.   

    string ii = this.father._dgv.Row[i].Cells[i].Text
      

  8.   

    大哥:这样做太麻烦了,给你一个好的建议,在GridView前面加上Checkboxlist去做。
      

  9.   

    还有个方法就是把datagridview里的数据放到datatable里面去
    datatable dt = new datatable();
    table.Columns.Add(...)
    DataRow row = table.NewRow();
    row[0]=..
      

  10.   

    这个问题!其实都不需要用到索引的
    this.tb1.Text = this.father._dgv.SelectedRows[0].Cells[0].Value.ToString(); 
    this.tb2.Text = this.father._dgv.SelectedRows[0].Cells[1].Value.ToString(); 
    this.tb3.Text = this.father._dgv.SelectedRows[0].Cells[2].Value.ToString();
    就可以实现了!不需要用到a
      

  11.   

    SelectedRows[0]这个地方用错是了应该是
    this.tb1.Text = this.father._dgv.SelectedRows[i].Cells[0].Value.ToString(); 
      

  12.   

    写错了,是这样的
    this.tb1.Text = this.father._dgv.Rows[i].Cells[0].Value.ToString();  
      

  13.   

    int index = ((DataGrid)sender).CurrentCell.RowNumber;             ((DataGrid)sender).Select(index);