2013-10-30 30 views
0

我有一個collectionviewsource項目。每個項目都是一個對象,它有一個屬性SentTime和另一個屬性ParentId。 我想組的項目由他們的ParentId,並給他們以下列方式排序:collectionviewsource中的特定排序分組項目

  • 一組中的項目應該由SentTime人354
  • 組應該由SentTime進行排序降序

下面是一個簡單的例子:發送1/10

  • 項目1,父ID 1
  • ITE米2發送2/10,父ID 1
  • 項目3已發送3/10,父ID 3
  • 項目4發送4/10,父ID 3
  • 項目5發送5/10,父ID 1

然後分組名單應該是這樣的:

項目3

  • 項目4

項目1

  • 項目2
  • 項目5

我有我的視圖模型collectionviewsource。

this.MyCvs.SortDescriptions.Clear(); 
this.MyCvs.SortDescriptions.Add(new SortDescription("SendTime", ListSortDirection.Ascending)); 
this.MyCvs.GroupDescriptions.Add(new PropertyGroupDescription("ParentId")); 

我知道,命令在CVS組我只需要由酒店,通過該項目的分組情況(在我的情況的ParentId)再添SortDescription但它不給我想得到的結果。 提前感謝大家的幫助。

回答

0

當您在網格中進行分組和排序時,您必須設置排序描述的方式與您所做的有所不同。

this.MyCvs.SortDescriptions.Clear(); 

this.MyCvs.GroupDescriptions.Add(new PropertyGroupDescription("ParentId")); 

this.FilteredMessages.SortDescriptions.Add(new SortDescription("ParentId", ListSortDirection.Ascending)); 
this.FilteredMessages.SortDescriptions.Add(new SortDescription("SendTime", ListSortDirection.Ascending)); 

這就是你如何實現,只有每個組應用排序。

+0

對不起,我犯了一個錯誤:沒有其他的CVS(我的意思是FilteredMessages應該是MyCvs)。我嘗試了你的答案,並且組中的項目排序正常,但這些組未按降序排序。 – kzub

+0

因爲您在ParentId上設置了升序,所以將按升序排序。設置降序,它會以其他方式工作。順便說一句,隨時標記這個答案或投票它,如果它解決了你的問題。 –