如何获得datagridview1当前行的值

zhengyingcan 2009-03-27 12:38:13
da.fill(ds,"sc");
datagridview1.datasource = ds.table["sc"];
datagridview1上面有数据的时候,
当我的鼠标在datagrid1上点击时,如何获得当前行各列的值呢 ,因为我想把当前的值赋到另外一个窗体上,该如何做呢
...全文
412 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhengyingcan 2009-03-28
  • 打赏
  • 举报
回复
我也很想做模板列,不会做呀,不知道如何做,请6楼的朋友教一下, 对dgv解释一下,非常感谢
jiyan1221 2009-03-28
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 zhengyingcan 的回复:]
序号TextBox.Text = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
为什么以上代码不能总是生效呢, 有的时候 序号TextBox 是对的,但大部分的时候,序号TextBox的值是不动的, 好奇怪.
[/Quote]
你的DGV里面没有用到模板列吗?用到的话要用FindControl找到里层的控件,取值或者赋值。
zhengyingcan 2009-03-28
  • 打赏
  • 举报
回复
序号TextBox.Text = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
为什么以上代码不能总是生效呢, 有的时候 序号TextBox 是对的,但大部分的时候,序号TextBox的值是不动的, 好奇怪.
benjaminwu198818 2009-03-28
  • 打赏
  • 举报
回复

// 单击 DataGridView 单元格时 获取DataGridView行的索引
int Index = DataGridViewName.Rows[DataGridViewName.SelectedCells[0].RowIndex].Cells[0].RowIndex;
根据行的索引把里面单元格的所有的值都取出来。。。传递给另外的窗体就可以了,至于怎么传递,方法很多…
ChinaITOldMan 2009-03-28
  • 打赏
  • 举报
回复
currentrow
qzw4549689 2009-03-28
  • 打赏
  • 举报
回复
当前 DGV的 选中行的 列 的值
this.dataGridView1.CurrentRow.Cells[0].Value.ToString(),其中cell[0]即第一列一次类推,亦可以直接写列名,如cell[ID]即ID列
tmd456 2009-03-28
  • 打赏
  • 举报
回复
string result = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
深海之蓝 2009-03-27
  • 打赏
  • 举报
回复
用 一个循环就可以 全部取出了
深海之蓝 2009-03-27
  • 打赏
  • 举报
回复
string result = this.dataGridView1.CurrentRow.Cells[0].Value.ToString().Trim();//当前行 第0列的值
wangping_li 2009-03-27
  • 打赏
  • 举报
回复

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

68435970 2009-03-27
  • 打赏
  • 举报
回复

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

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧