DataGrid如何行选中

sandhds 2003-09-11 01:14:54
DataGrid如何行选中
...全文
44 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
ArEoN 2003-09-11
  • 打赏
  • 举报
回复
我帮你写一个datagrid事件:单击datagrid中某个单元格即选定该行
private void yourDataGrid_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
System.Drawing.Point pt = new Point(e.X, e.Y);
DataGrid.HitTestInfo hit = this.yourDataGrid.HitTest(pt);
if(hit.Type == DataGrid.HitTestType.Cell)
{
this.yourDataGrid.CurrentCell = new DataGridCell(hit.Row, hit.Column);
this.yourDataGrid.Select(hit.Row);
}
}


顺便说一句,分这么重要么?给5分?
jrh9981 2003-09-11
  • 打赏
  • 举报
回复
增加一个选择列,可以把选择列跟数据列绑定,就可以选择一行了
peng0929 2003-09-11
  • 打赏
  • 举报
回复
int i = 7;
DataGrid1.SelectedIndex = i;
skykevin 2003-09-11
  • 打赏
  • 举报
回复
把dataGrid设置为只读属性,即使用户还可以在网格中用鼠标点击而选择某一格,但改不了其中的数据。
sandhds 2003-09-11
  • 打赏
  • 举报
回复
楼上两位大侠:
运用上面的方法设置以后,用户还可以在网格中用鼠标点击而选择某一格
我的意思是设置以后用户只能进行行选中了。
dotnba 2003-09-11
  • 打赏
  • 举报
回复
grd.Select(0)
skykevin 2003-09-11
  • 打赏
  • 举报
回复
CurrencyManager cm;

cm=(CurrencyManager) BindingContext[dataGrid1.DataSource];

如要让第行选中(小三角移到该行),则如下表示:
cm.Position=4

110,536

社区成员

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

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

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