2017-09-18 89 views
2

正在使用的DevExpress 16.1,我在我的數據表裝訂成XtraGrid中, 現在我想選擇通過縱列同時單擊列標題,如果有任何選項被XtraGrid中實現這一目標。select columnwise while devexpress xtragrid點擊columnheader?

。所有這些都是我試過,

gridview1.optionsselection.multiselect = True 
gridview1.optionsselection.multiselectMode = cellselect 
+0

單擊列標題將默認對列進行排序。您是否想禁用鼠標點擊對列進行排序的能力,或者您希望用戶可以按住某個鍵(如CTRL),同時單擊列標題進行選擇? – Brendon

+0

是的,我改變了,現在在列標題列cilck禁用,但我需要時點擊列標題其選擇列(垂直)數據 – Shankar

+0

您是否嘗試使用GridView的重載SelectCells方法來選擇列點擊? https://documentation.devexpress.com/WindowsForms/DevExpress.XtraGrid.Views.Grid.GridView.SelectCells.method(sh0-JQ) – Brendon

回答

2

試試這個代碼:(採用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方法被調用來獲得處理一行。焦點然後移動到此行並調用自定義上下文菜單。

相關問題