miercuri, 31 martie 2010

DevExpress: How to select a hole colu...

How to select a hole column in GridView (offered by DevExpress)? 


What I want: on mouse click to select all cells in the column.

public DevExpress.XtraGrid.Views.Grid.GridView m_gridview;
m_gridview.MouseUp += m_gridview_MouseUp;
protected virtual void m_gridview_MouseUp(object sender, MouseEventArgs e)
{
    GridHitInfo _newHitInfo = m_gridview.CalcHitInfo(e.X, e.Y);
    if (e.Button == MouseButtons.Left && _newHitInfo.HitTest == GridHitTest.Column)
    {
            if (!(m_gridview.IsSizingState && m_gridview.State == DevExpress.XtraGrid.Views.Grid.GridState.ColumnSizing))
            {
                   m_gridview.ClearSelection();
                   m_gridview.SelectCells(0, _newHitInfo .Column, m_gridview.RowCount - 1, _newHitInfo.Column);
             }
    }
}

Important to note:
 - use GridHitInfo.HitTest  to know if you are pressing on the column header
 - use GridView.IsSizingState and GridView.State properties to avoid selection when the column is resizing through dragging

Source: DevExpress online documentation.



Niciun comentariu:

Trimiteți un comentariu