我想知道vb.net中是否有datagridview标题右键单击事件。
在我的vb.net项目中,我有一个datagridview,每当我右键单击标题部分时,应用程序都会崩溃。有没有办法避免崩溃,例如添加事件处理程序或任何其他方法?
感谢。
与datagrid相关的代码:
UPDATE1 :
我的代码与datagrid有关,如下所示:
Private Sub Result_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
logger = log4net.LogManager.GetLogger("MyProject")
logger.Info("Result_Load() - Start")
Using connObj As New SqlClient.SqlConnection(My.Settings.dbConnectionString)
connObj.Open()
gridSql = "SELECT USER_ID, USER_NAME, USER_ADDRESS, USER_EMAIL FROM USER_DETAILS " & vbCrLf &
"WHERE USER_ID IN (" + Attribute.allUserSelected + ")"
' the Attribute.allUserSelected is pass from another form
logger.Info("gridSql= " + gridSql)
Try
adapter = New SqlDataAdapter(gridSql, connObj)
adapter.Fill(ds)
connObj.Close()
DataGridView1.DataSource = ds.Tables(0)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Using
Catch ex As Exception
MsgBox(ex.ToString)
logger.Error(ex.ToString)
Return
End Try
End Sub
Private Sub dataGridView1_ColumnHeaderMouseClick(ByVal sender As Object, ByVal e As DataGridViewCellMouseEventArgs) Handles DataGridView1.ColumnHeaderMouseClick
MsgBox("click the header....")
'I can get the message here
If (e.Button = MouseButtons.Right) Then
MsgBox("right click the header......")
'cannot get this ,message, crash immediately
End If
end Sub
请告诉我,谢谢。
答案 0 :(得分:0)
这种情况来得太晚了,但不会怀疑将来有些人会这么做。
DataGridView1. Columns ( 0). SortMode = DataGridViewColumnSortMode. NotSortable
您的列标题不会回复Left/Right Click