試試這個代碼:(採用Gridcontrol鼠標按下事件)
VB.net:
Dim hitInfo = GridView1.CalcHitInfo(e.Location)
If e.Button = Windows.Forms.MouseButtons.Left Then
For Each column As GridColumn In GridView1.Columns
If column.FieldName = hitInfo.Column.FieldName Then
hitInfo.Column.AppearanceCell.BackColor = Color.FromArgb(226, 234, 253)
Else
GridView1.Columns(column.FieldName).AppearanceCell.BackColor = Nothing
End If
Next
End If
C#:
var hitInfo = GridView1.CalcHitInfo(e.Location);
if (e.Button == Windows.Forms.MouseButtons.Left)
{
foreach (GridColumn column in GridView1.Columns)
{
if (column.FieldName == hitInfo.Column.FieldName)
{
hitInfo.Column.AppearanceCell.BackColor = Color.FromArgb(226, 234, 253);
}
else
{
GridView1.Columns(column.FieldName).AppearanceCell.BackColor = null;
}
}
}
的GridView.CalcHitInfo方法被調用來獲得處理一行。焦點然後移動到此行並調用自定義上下文菜單。
單擊列標題將默認對列進行排序。您是否想禁用鼠標點擊對列進行排序的能力,或者您希望用戶可以按住某個鍵(如CTRL),同時單擊列標題進行選擇? – Brendon
是的,我改變了,現在在列標題列cilck禁用,但我需要時點擊列標題其選擇列(垂直)數據 – Shankar
您是否嘗試使用GridView的重載SelectCells方法來選擇列點擊? https://documentation.devexpress.com/WindowsForms/DevExpress.XtraGrid.Views.Grid.GridView.SelectCells.method(sh0-JQ) – Brendon