如何在dataGrid中取得其绑定的基础数据表的行位置

bobjeey 2002-10-05 05:50:39
我在form 中放置datagrid 后,没有使用数据集控件,而是使用语句将一内存表做为
datagrid 的数据源,我用datagrid.bingdingcontext[数据表].position取行号,取得的总是第一行。请指教单击datagrid的某一行,正确取行号的方法。
...全文
26 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
ju_feng 2002-10-05
  • 打赏
  • 举报
回复
获得当前光标制定的行: dataGrid.currencell.rownum
通过帮定来实现:this.bindcontext(dataset).Current;
saucer 2002-10-05
  • 打赏
  • 举报
回复
if you want the row number of the DataGrid, handle MouseUp event:

private void dataGrid1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
System.Drawing.Point pt = new Point(e.X, e.Y);
DataGrid.HitTestInfo hti = dataGrid1.HitTest(pt);
if(hti.Type == DataGrid.HitTestType.Cell)
{
MessageBox.Show(hti.Row.ToString());
}
}


or try
dataGrid1.CurrentRowIndex

or

CurrencyManager cm;
cm=(CurrencyManager)YourDataGrid.BindingContext[YourDataGrid.DataSource];
DataRowView drv;
drv =(DataRowView) cm.Current;
DataRow myDataRow = drv.Row;

110,535

社区成员

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

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

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