da.fill(ds,"sc");
datagridview1.datasource = ds.table["sc"];
datagridview1上面有数据的时候,
当我的鼠标在datagrid1上点击时,如何获得当前行各列的值呢 ,因为我想把当前的值赋到另外一个窗体上,该如何做呢
datagridview1.datasource = ds.table["sc"];
datagridview1上面有数据的时候,
当我的鼠标在datagrid1上点击时,如何获得当前行各列的值呢 ,因为我想把当前的值赋到另外一个窗体上,该如何做呢
解决方案 »
- GridView1.DataSource定时变换
- 求助像素循环问题
- 怎么在程序中测试中向Imagelist添加图片,并且再下次测试的时候能够看到新添加的图片!
- 用c#开发的office2003程序与office2007程序,代码相同吗?是否能互相兼容
- 各位大大:我怎么判断一个字符串是否在另一个字符串中呢?
- string S = "ABC"; S[1] = '1'; 出错。如何解决?
- 如何实现在web上让用户自定义颜色?
- 高手请进, comboBox.text 的问题
- 各位大哥, 谁有这本书 Pro NET 2.0 Windows Forms and Custom Controls in C#?
- 请教!在操作多个数据库时,除了选择com+的事务,可以使用连接事务吗?
- 新手求助
- sharp develop 和 VC#2005 写简单的数据库程序有差别吗?
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
//你点击那一行的第一列值
string strId = dataGridView1[1, e.RowIndex].Value.ToString().Trim();
}
}
DataGridViewRow currentrow=dataGridView.CurrentRow;
if(currentrow!=null)
{
String str=currentrow.Cells["字段名"].Value.ToString();
}
为什么以上代码不能总是生效呢, 有的时候 序号TextBox 是对的,但大部分的时候,序号TextBox的值是不动的, 好奇怪.
this.dataGridView1.CurrentRow.Cells[0].Value.ToString(),其中cell[0]即第一列一次类推,亦可以直接写列名,如cell[ID]即ID列
// 单击 DataGridView 单元格时 获取DataGridView行的索引
int Index = DataGridViewName.Rows[DataGridViewName.SelectedCells[0].RowIndex].Cells[0].RowIndex;
根据行的索引把里面单元格的所有的值都取出来传递给另外的窗体就可以了,至于怎么传递,方法很多…