如何在具有分组的 Silverlight DataGrid 上启用排序? [英] How do you enable sorting on a Silverlight DataGrid that has grouping?

查看:33
本文介绍了如何在具有分组的 Silverlight DataGrid 上启用排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎找不到一种方法来指定它首先按组名排序,然后按列排序.我正在使用 DataGrid.

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.

我的错误,我使用的是 DataGrid,而不是 Grid.

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

推荐答案

Grid 不是数据控件(如 DataGrid),所以除了手动排序然后一一添加其他项目之外,真的没有干净方法.

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.

您需要将网格视为 HTML 表格标记的 XAML 版本.

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

EDIT(OP 从 Grid 更改为 DataGrid,添加以下内容):

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

内置对 DataGrid 排序的支持,用于对实现 IList 接口的任何集合进行排序.如果您使用的是 AutoGenerateColumns,那就是它了.但这听起来不像你想要做的.

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.

听起来您正在尝试以编程方式进行操作.您需要做的是设置列的 SortMemberPath.如果您手动创建列,它只是列上的一个属性.如果您使用自动生成,则可以在 AutoGeneratingColumn 事件中进行.

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.

如果您也在 XAML 中手动创建列,您也可以通过设置列的属性在 XAML 中执行此操作.

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.

请记住,这些只是在 DataGrid 中进行排序的一般说明.对于更复杂的排序(例如您正在查询),您需要对正在使用的数据源进行排序,即您要将网格绑定到的集合.

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.

这篇关于如何在具有分组的 Silverlight DataGrid 上启用排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆