This is a migrated thread and some comments may be shown as answers.

Creating and filtering a grid, then returning rowset

2 Answers 53 Views
GridView
This is a migrated thread and some comments may be shown as answers.
scott
Top achievements
Rank 1
scott asked on 03 Aug 2010, 07:26 PM

Hi.  I have a grid with a DataTable as its ItemsSource.  I need to answer the question: What DataTable rows are left if I apply a bunch of saved filters to this DataTable ?  So I'm trying to:

public List<DataRow> GetList(DataTable dt)
{
    DataTable myTable = DupTable(dt);
    RadGridView myGrid = new RadGridView() { ItemsSource = myTable, Visibility = Visibility.Visible, EnableRowVirtualization=false };
    myGrid.Filtered += new EventHandler<GridViewFilteredEventArgs>(myGrid_Filtered);
    myGrid.Items.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(Items_CollectionChanged);
    foreach (ColumnFilterDescriptor fd in myfilters)
        myGrid.FilterDescriptors.Add(fd);
    IList<GridViewRow> list = myGrid.ChildrenOfType<GridViewRow>();
    List<DataRow> results = new List<DataRow>();
    foreach (GridViewRow gvr in list)
        results.Add(gvr.Item as DataRow);
    return results;

The problem with this approach is that myGrid.ChildOfType<GridViewRow> is returning empty and I don't know why that is.  I've been playing with visibility and virtualization trying to get some data back but no success. Using the collection changed event I can see that the data are going into the grid and being filtered correctly... I just need to get the DataRows back out of the grid...

Can somebody please tell me why myGrid.ChildrenOfType<GridViewRow> might be empty ?

Thank you -
Scott

2 Answers, 1 is accepted

Sort by
0
scott
Top achievements
Rank 1
answered on 03 Aug 2010, 07:52 PM
Just hacking at this problem... This seems to work :)

 


//foreach (GridViewRow gvr in list)
//    results.Add(gvr.Item as DataRow);
for (int i = 0; i < myGrid.Items.Count; i++)
{
    DataRow row = myGrid.Items[i].GetType().GetProperty("DataRow").GetValue(myGrid.Items[i], null) as DataRow;
    results.Add(row);
}


Any big difference ?
0
Vlad
Telerik team
answered on 06 Aug 2010, 08:00 AM
Hello,

Our DataTable will create dynamic objects with real properties from the original rows and that is why Items will return these object instead original. 

Best wishes,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
scott
Top achievements
Rank 1
Answers by
scott
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or