1

I've got an 'XceedDataGridWrapper' in an application which is bound to some data. In the C# file behind the XAML for the file which holds my dataset I have a variable which holds a reference to the Xceed data-grid:

public XceedDataGridWrapper GridWrapper;

Is there a simple method of getting all of the content that is currently visible on the grid (so if a user applies a filter of some kind, it will return only the items that are being shown)?

In the ideal world I'd like to be able to something similar to this:

var dataContext = GridWrapper.CurrentItems;

But I don't clearly see a method anywhere to do that.

Help is appreciated!

AidanH
  • 502
  • 5
  • 24
  • Look into `MVVM` and `CollectionViewSource`. – jsanalytics Jan 12 '18 at 10:37
  • Would you be able to give any pointers on how to use CollectionViewSource? We already have an MVVM setup. – AidanH Jan 12 '18 at 10:44
  • But you need to grasp MVVM, because what you want to do in your _ideal world_ line of code sample, doesn't fit that. As for `CollectionViewSource` there's plenty of samples/tutorials out there, just search it. – jsanalytics Jan 12 '18 at 10:49
  • It's a semi-MVVM setup, we all understand MVVM but the previous programmers who made the project didn't uncouple everything from the UI. I'm currently only testing, but I just want to be able to quickly get the visible data from the grid. - I'll look into CollectionViewSource – AidanH Jan 12 '18 at 10:53

1 Answers1

1

It turns out that 'XceedDataGridWrapper' has a 'CollectionViewSource' in it (thanks for the pointer @jsanalytics), however it was stored in a private property called 'mviewsource' So what I did was expose it as a dependency property:

public static readonly DependencyProperty CurrentDataProperty =
        DependencyProperty.Register(
            "CurrentData",
            typeof(DataGridCollectionView),
            typeof(XceedDataGridWrapper),
            new UIPropertyMetadata(null));

public DataGridCollectionView CurrentData
{
    get { return mviewSource; }
}

And then I could access the 'CollectionView' from outside the 'XceedDataGrid'.

jsanalytics
  • 13,058
  • 4
  • 22
  • 43
AidanH
  • 502
  • 5
  • 24