请教DataGrid控件中如何为MouseDown事件划定行范围?

acmepoyen 2004-07-22 12:11:19
请教DataGrid控件中如何为MouseDown事件划定行范围?
已经画好了为点击DataGrid控件中相关行的FORM窗口,FORM窗口中提供要修改的单元格值,目的是当点击相应的单元格的时候弹出相对应的FORM窗口,并赋值该单元格,并存储至数据集。现在一直搞不懂怎么确定MouseDown的点击范围,比如第3至第6行的FORM窗口是一样的,可是点第7行也会出现同样的窗口,FORM窗口没有唯一性了,单元格的行列值我也获取了,可是就是不会弄#$%^@# 晕的很……
是不是用CurrentCellChanged事件比MouseDown事件要好用?
又比如第7行和第18行的FORM窗口是一样的,这种跨行的范围如何确定啊?

谢谢啦!
...全文
79 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
水如烟 2004-07-22
要实现你原来的想法不是不行,方法也好多,只是我觉得太不实际了(通用性差,不好变通)
所以应该不强求这种做法了
其实一变通,什么事都好办
回复
acmepoyen 2004-07-22
谢谢啊~ 不过我找到一种更好的方法,不知道如何?请大家看看:



Private Sub DataGrid1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGxiangmu.MouseDown

DataGridRC = Me.DataGrid1.HitTest(e.X, e.Y)
Dim Form4 As New Form4
If Me.DataGridRC.Row > 3 And Me.DataGridRC.Row < 7 Then
Form4.GroupIndex = 2
Form4.WindowX = Me.MousePosition.X
Form4.WindowY = Me.MousePosition.Y
Form4.ShowDialog()
Else
Form4.GroupIndex = 1
Form4.WindowX = Me.MousePosition.X
Form4.WindowY = Me.MousePosition.Y
Form4.ShowDialog()
End If

End Sub
回复
VC_j 2004-07-22
DataGridRC 是什么数据类型啊??
是自定义的吗?楼主,???
回复
水如烟 2004-07-22
觉得你这种思路不妥,如果有一天你需要改动数据,就可能错乱了行、form关系,那不是自乱阵脚。
可以这样,根据你的条件,在DataTable中加一个Column,只是不显示它在DataGrid上,
那样,你只用根据它的值调用相应的Form就行了。
回复
terryxin 2004-07-22
兄弟们,怎么没有人回答问题啊啊,
回复
VC_j 2004-07-22

看看下面的代码,
---------------------------------------------------------------------------------
Private Sub DataGrid1_Navigate(ByVal sender As System.Object, ByVal ne As System.Windows.Forms.NavigateEventArgs) Handles dgCustomer.Navigate

End Sub

Private Sub dgCustomer_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dgCustomer.MouseDown

Dim myGrid As DataGrid = CType(sender, DataGrid)

Dim hti As System.Windows.Forms.DataGrid.HitTestInfo

hti = myGrid.HitTest(e.X, e.Y)

Select Case hti.Type 'the following code is used to show the CASE content

Case System.Windows.Forms.DataGrid.HitTestType.None

MsgBox("You click the background")

Case System.Windows.Forms.DataGrid.HitTestType.Cell

MsgBox("you click the cell row£º" & hti.Row & ", Column£º" & hti.Column)

Case System.Windows.Forms.DataGrid.HitTestType.ColumnHeader

MsgBox("you click the column number" & hti.Column & "the head of the column")

Case System.Windows.Forms.DataGrid.HitTestType.RowHeader

MsgBox("you click the row number " & hti.Row & "the head of the row")

Case System.Windows.Forms.DataGrid.HitTestType.ColumnResize

MsgBox("you click number:" & hti.Column & "the fram of column")

Case System.Windows.Forms.DataGrid.HitTestType.RowResize

MsgBox("you click number" & hti.Row & "the fram of the row")

Case System.Windows.Forms.DataGrid.HitTestType.Caption

MsgBox("you click the title ")

Case System.Windows.Forms.DataGrid.HitTestType.ParentRows

MsgBox("you click the parant rows ")

End Select



End Sub


Private Sub OleDbConnection1_InfoMessage(ByVal sender As System.Object, ByVal e As System.Data.OleDb.OleDbInfoMessageEventArgs) Handles oconCat.InfoMessage

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.DsCustomer.Clear()
Me.odaCustomer().Fill(DsCustomer)

End Sub
End Class
回复
相关推荐
发帖
VB
创建于2007-09-28

1.6w+

社区成员

VB技术相关讨论,主要为经典vb,即VB6.0
申请成为版主
帖子事件
创建了帖子
2004-07-22 12:11
社区公告
暂无公告