在列样式中绑定AddHandler col2.TextBox.DoubleClick, AddressOf mycell_doubleclick,c2是列样式 Private Sub DataGrid1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseDown If e.Button = MouseButtons.Left Then 'And e.Clicks = 2 当加上前面这句后得不到结果的,因为没有那么敏感的 Dim myHitTest As DataGrid.HitTestInfo myHitTest = DataGrid1.HitTest(e.X, e.Y) If myHitTest.Type = DataGrid.HitTestType.Cell Then nowdatetime = Now() End If End If End Sub '如果光标进入datagrid和textbox的间隔时间小于系统的默认的鼠标双击时间,则说明是在datagrid中双击的 Private Sub mycell_mousedown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) If (DateTime.Now < nowdatetime.AddMilliseconds(SystemInformation.DoubleClickTime)) Then gotofrmmaterial() End If End Sub
Private Sub DataGrid1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseDown
If e.Button = MouseButtons.Left Then 'And e.Clicks = 2 当加上前面这句后得不到结果的,因为没有那么敏感的
Dim myHitTest As DataGrid.HitTestInfo
myHitTest = DataGrid1.HitTest(e.X, e.Y)
If myHitTest.Type = DataGrid.HitTestType.Cell Then
nowdatetime = Now()
End If
End If
End Sub
'如果光标进入datagrid和textbox的间隔时间小于系统的默认的鼠标双击时间,则说明是在datagrid中双击的
Private Sub mycell_mousedown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
If (DateTime.Now < nowdatetime.AddMilliseconds(SystemInformation.DoubleClickTime)) Then
gotofrmmaterial()
End If
End Sub
这里面有一小段是专讲这个的设计思想,你可以参考一下。
private void dgGoods_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.SelectedItem)
{
e.Item.Attributes.Add("ondblclick",Page.GetPostBackClientEvent(((Button)e.Item.Cells[0].Controls[0]),"")) ; //非正在编辑的项双击后模拟点击隐藏的编辑按钮。 }
}private void dgGoods_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if(e.CommandName == "btnDbClick")
{
Response.Write("<script>alert('"+e.Item.Cells[1].Text+"');</script>");
////////////////////////////看看什么结果
}
}