2
votes

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   
1
Clicking on a column header will sort the column by default. Do you want to disable the ability to sort the column on mouse click, or do you expect that your users might press and hold a key (such as CTRL) while clicking the column header to select it? - Brendon
yes i changed that , now cilck on column header sort is disable, but i need when click column header its selecting column(verticalwise) data - Shankar
Did you try using the GridView's overloaded SelectCells method to select a range of cells in the column which is clicked? documentation.devexpress.com/WindowsForms/… - Brendon

1 Answers

2
votes

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.