开发者

Get the Grid data in ColumnHeaderClick

Sorrry guys, I'm stuck here.

I have a few grids, I also have CollectionViewSource objects associated with those grids.

Now, I'm trying to apply CollectionViewSource.SortDescriptions in ColumnHeaderClick method, and now I have to define almost the sam开发者_如何学编程e method for each grid.

But the only thing I really need is to obtain in which Grid is happenning.

How to get that, I have no idea. Help me please.

VisualTreeHelper.GetParent didn't work.


I think, probably, the best thing would be to derive your own grid control, adding the common functionality that you want. as for finding the the column that was clicked, here is some source code....

protected override void OnPreviewMouseLeftButtonUp(MouseButtonEventArgs e)
{
   base.OnPreviewMouseLeftButtonUp(e);
   if ( e.OriginalSource is GridViewColumnHeader)
   {
      GridViewColumn col = ((GridViewColumnHeader)e.OriginalSource).Column as GridViewColumn;
     DoStuffWithYourColumn( col );
   }
}

oh, and one thing, you really should use the custom sorter instead of sort descriptions--sort descriptions are REALLY slow. take a look at this article for more information on the subject.


Oh.. it's turned out that it's possible to change the SortDesriptions directly in

(((System.Windows.Controls.ListBox)(sender)).Items)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜