在WinForm窗体中,在其放一个datagridview控件和一个textbox控件,然后我用鼠标点击datagridview中的记录时,datagridview中的相应记录会在textbox中显示出来……——

解决方案 »

  1.   

    就是要能够自由选择一行,然后要获取到这个行的索引号,才能对textbox控件进行赋值……
      

  2.   

    selectRows[e.index]表示的是当前选中的行,e.index就是当前行的索引 哦
      

  3.   

    int rowindex = this.dataGridViewitem.CurrentRow.Index;                     //获取选中的行
    textbox.Text Code = this.dataGridViewitem[0, rowindex].Value.ToString();   //获取选中行的第一个单元格
      

  4.   

    private void dgvMpswecone_CellClick(object sender, DataGridViewCellEventArgs e)
            {
                if (e.RowIndex > -1) //判断是否是表头
                {
                    TextBox tx = dgvMpswecone.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
                }
                
            }
      

  5.   

    简单的处理是datagridiew数据源不要直接用datatable,而是用Bindingsource对象,而把Bindingsourc对象的数据源设置成为你的datatable。
    这样你可以直接获取BindingSource对象的Position属性得到你当前选择的索引值
      

  6.   

    int rowindex = this.dataGridViewitem.CurrentRow.Index; //获取选中的行textbox.Text Code = this.dataGridViewitem[0, rowindex].Value.ToString(); //获取选中行的第一个单元格 int cellCount = AllLinkmanGridView.SelectedCells.Count;//获取选择行的列总数string cellValue = AllLinkmanGridView.SelectedCells[0].Value.ToString();//获取选择行的第一列
      

  7.   

    不明白为什么3楼和6楼要在textbox.Text后面加个Code……我是新手……不过我不加好像可以运行……加了反倒不行。学习了!
      

  8.   

    不用code吧.直接赋值就可以了啊
      

  9.   

    应该是  selectedindex这个属性
      

  10.   

    textBox1.Text=dataGridView1.CurrentRow.Cells[1].Value .ToString();