da.fill(ds,"sc");
datagridview1.datasource = ds.table["sc"]; 
datagridview1上面有数据的时候,
当我的鼠标在datagrid1上点击时,如何获得当前行各列的值呢 ,因为我想把当前的值赋到另外一个窗体上,该如何做呢

解决方案 »

  1.   


      private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
            {
                if (e.RowIndex >= 0)
                {
                   //你点击那一行的第一列值
                   string strId = dataGridView1[1, e.RowIndex].Value.ToString().Trim();
                }
            }
      

  2.   


    DataGridViewRow currentrow=dataGridView.CurrentRow;
    if(currentrow!=null)
    {
       String str=currentrow.Cells["字段名"].Value.ToString();
    }
      

  3.   

    string result = this.dataGridView1.CurrentRow.Cells[0].Value.ToString().Trim();//当前行 第0列的值
      

  4.   

    序号TextBox.Text = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();   
    为什么以上代码不能总是生效呢, 有的时候 序号TextBox 是对的,但大部分的时候,序号TextBox的值是不动的, 好奇怪.
      

  5.   

    你的DGV里面没有用到模板列吗?用到的话要用FindControl找到里层的控件,取值或者赋值。
      

  6.   

    我也很想做模板列,不会做呀,不知道如何做,请6楼的朋友教一下, 对dgv解释一下,非常感谢
      

  7.   

    string result = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
      

  8.   

    当前     DGV的          选中行的    列        的值
    this.dataGridView1.CurrentRow.Cells[0].Value.ToString(),其中cell[0]即第一列一次类推,亦可以直接写列名,如cell[ID]即ID列
      

  9.   


    // 单击 DataGridView 单元格时 获取DataGridView行的索引 
    int Index = DataGridViewName.Rows[DataGridViewName.SelectedCells[0].RowIndex].Cells[0].RowIndex;
    根据行的索引把里面单元格的所有的值都取出来传递给另外的窗体就可以了,至于怎么传递,方法很多…