请问大家,DataGrid选定某行怎么表示?

safematch 2004-12-13 09:45:26
我想对DataGrid的某行操作,应该用哪个属性,为什么在WebForm的DataGrid成员就有SelectIndex,而WinForm的DataGrid就没有这个成员了呢?我想在选中某列这个事件里执行程序,只找到了CurrentCellChanged这个事件,难道WinForm的DataGrid压根就没有这种成员吗?
请指教
...全文
126 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
safematch 2004-12-13
  • 打赏
  • 举报
回复
呵呵,我太偷懒了,忘了加。
谢谢二位啊。
北京的雾霾天 2004-12-13
  • 打赏
  • 举报
回复
你把Handles DataGrid1.MouseDown加上啊:


Private Sub DataGrid1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles DataGrid1.MouseDown
Dim hti As DataGrid.HitTestInfo
hti = DataGrid1.HitTest(New Point(e.X, e.Y))
Select Case hti.Type
Case System.Windows.Forms.DataGrid.HitTestType.None
Console.WriteLine("You clicked the background.")
Case System.Windows.Forms.DataGrid.HitTestType.Cell
Console.WriteLine("You clicked cell at row " & hti.Row & ", col " & hti.Column)
Case System.Windows.Forms.DataGrid.HitTestType.ColumnHeader
Console.WriteLine("You clicked the column header for column " & hti.Column)
Case System.Windows.Forms.DataGrid.HitTestType.RowHeader
Console.WriteLine("You clicked the row header for row " & hti.Row)
Case System.Windows.Forms.DataGrid.HitTestType.ColumnResize
Console.WriteLine("You clicked the column resizer for column " & hti.Column)
Case System.Windows.Forms.DataGrid.HitTestType.RowResize
Console.WriteLine("You clicked the row resizer for row " & hti.Row)
Case System.Windows.Forms.DataGrid.HitTestType.Caption
Console.WriteLine("You clicked the caption")
Case System.Windows.Forms.DataGrid.HitTestType.ParentRows
Console.WriteLine("You clicked the parent row")
End Select
End Sub
北京的雾霾天 2004-12-13
  • 打赏
  • 举报
回复
WinForm中,怎么会没有反映呢?
MyNetLand 2004-12-13
  • 打赏
  • 举报
回复

DataGrid对象有事件支持的。

在DataGrid对象中添加命令按钮。
设置命令按钮的CommandName属性。
在DataGrid对象的ItemCommand或SelectCommand事件中编写代码。
//主要使用事件的e.Item参数。
safematch 2004-12-13
  • 打赏
  • 举报
回复
我试了,点了以后没有反应啊,没起作用?
safematch 2004-12-13
  • 打赏
  • 举报
回复
谢谢这位兄台,hti.Row就是我想要得了吗?可以得到这行的数据吗?
北京的雾霾天 2004-12-13
  • 打赏
  • 举报
回复
这样做:
Private Sub DataGrid1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
Dim hti As DataGrid.HitTestInfo
hti = grid.HitTest(New Point(e.X, e.Y))
Select Case hti.Type
Case System.Windows.Forms.DataGrid.HitTestType.None
Console.WriteLine("You clicked the background.")
Case System.Windows.Forms.DataGrid.HitTestType.Cell
Console.WriteLine("You clicked cell at row " & hti.Row & ", col " & hti.Column)
Case System.Windows.Forms.DataGrid.HitTestType.ColumnHeader
Console.WriteLine("You clicked the column header for column " & hti.Column)
Case System.Windows.Forms.DataGrid.HitTestType.RowHeader
Console.WriteLine("You clicked the row header for row " & hti.Row)
Case System.Windows.Forms.DataGrid.HitTestType.ColumnResize
Console.WriteLine("You clicked the column resizer for column " & hti.Column)
Case System.Windows.Forms.DataGrid.HitTestType.RowResize
Console.WriteLine("You clicked the row resizer for row " & hti.Row)
Case System.Windows.Forms.DataGrid.HitTestType.Caption
Console.WriteLine("You clicked the caption")
Case System.Windows.Forms.DataGrid.HitTestType.ParentRows
Console.WriteLine("You clicked the parent row")
End Select
End Sub
safematch 2004-12-13
  • 打赏
  • 举报
回复
楼上的哥哥好快,可是事件是什么呢?
北京的雾霾天 2004-12-13
  • 打赏
  • 举报
回复
例如:
myDataGrid.Select(myDataGrid.CurrentRowIndex)
myDataGrid.UnSelect(myDataGrid.CurrentRowIndex)

safematch 2004-12-13
  • 打赏
  • 举报
回复
不好意思,说得有点乱。我就是想点击表的一行,执行一段代码,可是找不到该用哪个事件。
北京的雾霾天 2004-12-13
  • 打赏
  • 举报
回复
DataGrid.CurrentRowIndex

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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