dt1.Rows[dg1.CurrentRowIndex]["编号"].ToString().Trim()
其中dt1是与datagrid绑定的表,dg1是datagrid,编号是表中的字段
其中dt1是与datagrid绑定的表,dg1是datagrid,编号是表中的字段
解决方案 »
- 高分求救,如何唤醒处于待机状态的电脑!
- 人事系统
- The type of the name '' could not be found 是什么问题?
- 请问支线程运行完了,怎样回到主线程?
- 怎么在内存dataset里面的表进行sql语句联合表查询
- 加班,解决问题才能走人,求救诸位
- (接上贴)c# 在 socket通信中,多客户端与一个服务器端异步通信时,传图片没有问题,但两台客户端同时要求传视频会卡死,怀疑是数据发送与接收的问题,求赐教~
- hi,大家来看看这个题目,关于算法的
- 大家说一说foreach一个datatable和用for(int i=0;i<mytable.rows.count;i++)去遍历的区别。
- 为什么 i 仍旧是 5 ,已经 ++ 了 呀
- DataGrid编辑更新数据问题,请各位高手指点!
- vb中space(10)在c#中怎样写?
具体我也记不太清,反正有代码提示功能,试试看不就知道了
DataRow currRow;
DataColumn myColumn;
DataTable dataGridTable = (DataTable)DataGrid1.DataSource;
// Set the current row using the RowNumber property of the CurrentCell.
currRow = dataGridTable.Rows[DataGrid1.CurrentCell.RowNumber];
myColumn = dataGridTable.Columns[1];
// Get the value of the column 1 in the DataTable.
Console.WriteLine(currRow[myColumn, DataRowVersion.Current]);
}
看你是什么情况下使用了
一般如果通过事件触发的话
就用e.item....就可以
如果只是为了得出选中的
可以遍历或者得出dg.selectindex或者selectItem都可以定位到行
然后就可以类似e.Item.FindControl("lblRoomID")).Text;或者e.Item.cell[0].text
来获得
for(int i=0;i<dataGrid1.ListManager.Count;i++)
if(dataGrid1.IsSelected(i))
temp.Add(((DataView)(dataGrid1.DataSource))[i]);
return temp;其中dataGrid1.DataSource 连接的是Table.DefaultView
.CurrentCell.RowNumber; .IsSelected(...)
如果你想同DataSet对应
就必须考虑排序的问题
能实现的方法多着呢
{
bzh_tbx.Text=this.grd_hb[grd_hb.CurrentCell.RowNumber,1].ToString(); mlmc_tbx.Text=this.grd_hb[grd_hb.CurrentCell.RowNumber,3].ToString();
ym_tbx.Text=this.grd_hb[grd_hb.CurrentCell.RowNumber,2].ToString();
dz_tbx.Text=this.grd_hb[grd_hb.CurrentCell.RowNumber,0].ToString();
fs_tbx.Text=this.grd_hb[grd_hb.CurrentCell.RowNumber,6].ToString();
cbx_zf.Text=this.grd_hb[grd_hb.CurrentCell.RowNumber,4].ToString();
zfsj_tbx.Text=this.grd_hb[grd_hb.CurrentCell.RowNumber,5].ToString();
}
得到所选择的记录了几好办了!!
楼主是为了取出当前行对应的DataTable的值。
如下:
DataRowView drv = (DataRowView)this.BindingContext[this.ds,this.ds.Tables[0].TableName].Current;
获取到drv就可以改数据了
还可以获取
DataRow drow = drv.Row;