Home Forums WPF controls Xceed DataGrid for WPF Knowing which column was the last sorted column?

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

    Is there a way to know which column was the last sorted column?

    Here’s how I’m using the DataGridControl:

    myDataGridControl.SelectionMode = SelectionMode.Single
    myDataGridControl.ReadOnly = True
    myDataGridControl.CellEditorDisplayConditions = CellEditorDisplayConditions.None
    myDataGridControl.NavigationBehavior = NavigationBehavior.RowOnly

    I’m trying to implement this feature: if a user clicks on a letter, the focus should be placed on the first row where the cell’s content starts with the clicked letter. In addition, since there are multiple columns per row, the cell content depends on the last sorting.

    For example, let’s say I have a datagridcontrol with multiple columns, including one column for first name and one column for last name. If I sort by first name and then click on “S”, I’m taken to the row where the first name is “Sam”. But if I sort by last name and click on “S”, I’m taken to the row where the first name is “Smith”.

    Imported from legacy forums. Posted by Emmanuel (had 2915 views)

    Xceed Support
    Member
    Post count: 5658

    You can determine the grouping order by looking at the DataGridControl.Items.GroupDescriptions collection.

    The last entry in the collection represents the last sorted “property” (not directly “Column”). But you can then easilly relate the PropertyGroupDescription.PropertyName to a Column.FieldName from the DataGridControl.Columns collection.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 255 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi Marcus,

    Thanks for the tip, I knew there was some better way than just to hook up an event handler and “remember” the last column that was clicked on.

    Unfortunately the GroupDescriptions collection seems to be empty regardless of whether I have sorted (clicked on a column title) or not:

    myDataGridControl.Items.GroupDescriptions.Count -> is always = 0

    Is there an extra step I need to do to make sure there are items in the myDataGridControl.Items.GroupDescriptions ? Remember that I’m just in “grid” mode and I set the NavigationBehavior to NavigationBehavior.RowOnly.

    Imported from legacy forums. Posted by Emmanuel (had 445 views)

    Xceed Support
    Member
    Post count: 5658

    My mistake, you should observe the SortDescriptions collection to dermine the last column sorted by.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 4049 views)

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