Home Forums WinForms controls Xceed Grid for WinForms Programmatically AND manually sorting the columns.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #14918 |

    Hi

    I have a basic sort order that looks like this:
    dgParameters.Columns[“group”].SortDirection = SortDirection.Ascending;
    dgParameters.Columns[“parameter”].SortDirection = SortDirection.Ascending;

    (the grid is grouped by group)

    But I also want the user to be able to sort by other columns or the parameter column descending. The problem is that the basic sort (described above) disappears when the user is clicking the column. For example I’d like to sort by a column named Value, but I don’t want the grouping to be messed up.

    I’ve tried to override this by using the SortedColumnsChanged event like this:

    private void dgParameters_SortedColumnsChanged(object sender, EventArgs e)
    {
    Xceed.Grid.Column column = dgParameters.Columns[“group”];
    if(column != null && column.SortDirection == SortDirection.None)
    {
    column.SortDirection = SortDirection.Ascending;
    }

    What happens then is that NO column can be sorted descendingly. I’ve also tried to use the Sorted event without any luck.

    Can I somehow determine which column was clicked, it’s original state and it’s “attemted state”?

    //peter

    Imported from legacy forums. Posted by Peter (had 2797 views)

    User (Old forums)
    Member
    Post count: 23064

    oups! Missed a part of my code. The method should look like this:

    private void dgParameters_SortedColumnsChanged(object sender, EventArgs e)
    {

    this.dgParameters.SortedColumnsChanged -= new EventHandler(dgParameters_SortedColumnsChanged);

    Xceed.Grid.Column column = dgParameters.Columns[“group”];
    if(column != null && column.SortDirection == SortDirection.None)
    {
    column.SortDirection = SortDirection.Ascending;
    }

    this.dgParameters.SortedColumnsChanged += new EventHandler(dgParameters_SortedColumnsChanged);

    }

    Imported from legacy forums. Posted by Peter (had 442 views)

    User (Old forums)
    Member
    Post count: 23064

    Here is an option if the GroupByRow is not displayed.

    You can derive from ColumnManagerCell and ColumnManagerRow, override the OnClick, not call base, and add code so it sort the way you want.

    It should look something like this :

    protected override void OnClick( EventArgs e )
    {
    Column parentColumn = this.ParentColumn;

    if( ( parentColumn != null ) &&
    ( parentColumn.CanBeSorted ) &&
    ( this.MouseState == ColumnManagerCellMouseState.ColumnPressed ) )
    {
    this.SortColumn();
    }
    }

    Imported from legacy forums. Posted by André (had 3465 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.