How do you enable sorting on a Silverlight DataGrid that has grouping?

Deadly 提交于 2019-12-25 04:42:52

问题


I can't seem to find a way to specify that it sorts on the group name first, then the column. I am using the DataGrid.

EDIT: My mistake, I am using the DataGrid, not the Grid.


回答1:


A Grid is not a data control (like a DataGrid) so other than manually sorting and then adding the other items one-by-one, there's really no clean way to do it.

You need to think of a Grid as a XAML version of an HTML Table tag.

EDIT (OP changed from Grid to DataGrid, adding the following):

Support for sorting the DataGrid is built in for sorting any collection that implements the IList interface. If you're using AutoGenerateColumns that's all there is too it. But that's not what it sounds like you're wanting to do.

It sounds like you're trying to do it programatically. What you need to do is set the SortMemberPath of the column. If you're manually creating the columns, it's just a property on the column. If you're using autogeneration, you can do it in the AutoGeneratingColumn event.

You can do it in XAML too by just setting the property for the column, if you're creating the column manually in XAML too.

Bear in mind that these are just general instructions for sorting in a DataGrid. For a more involved sort such as you are inquiring about, you'll want to sort the data source you're using, i.e. the collection that you're binding the grid to.

What I'm unsure of is what you mean by "the group name first, then the column". Are you meaning group name as a default sort and then column sortation if the user desires? If so, these instructions should help. If not, I'm unsure what you mean.



来源:https://stackoverflow.com/questions/8346877/how-do-you-enable-sorting-on-a-silverlight-datagrid-that-has-grouping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!