Search code examples
c#vb.netdevexpressxtragrid

select columnwise while click columnheader in devexpress xtragrid?


Am using devexpress 16.1, i bind my datatable into xtragrid, now i want to select by columnwise while click column header, if there any option to achive this by xtragrid.

these are all things am tried ,

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

Solution

  • Try This Code:(Using Gridcontrol Mouse Down Event)

    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;
            }
        }
    }
    

    The GridView.CalcHitInfo method is called to obtain a row handle. Focus is then moved to this row and the custom context menu called.