Function to Clone DataView with new sort column(s)

I have a filtered DataView and I wanted to search it using different keys that was used for sorting.

Ther is no function out-of-the-box, so I created a helper method

public static DataView CloneDataView(DataView vwSource,string newSort)      
 {
    return new DataView(vwSource.Table ,vwSource.RowFilter,newSort,vwSource.RowState) ;
}

 Another function to create new DataView with extra filter:

        public static DataView NewDataViewWithExtraFilter(DataView vwSource, string newFilter)
        {
            string sFilter = vwSource.RowFilter;
            if (String.IsNullOrEmpty(sFilter))
            {
                sFilter = newFilter;
            }
            else
            {
                sFilter += String.Format(" and ( {0} )", newFilter);
            }
            DataView newDV = new DataView(vwSource.Table, sFilter, vwSource.Sort, vwSource.RowStateFilter);
           return newDV;
        }

posted @ Thursday, March 02, 2006 1:20 PM

Print

Comments on this entry:

# re: Function to Clone DataView with new sort column(s)

Left by ahsan at 4/12/2007 12:37 AM
Gravatar
Thank you so much .. simple yet elegent :p

ahsan
fastian7@gmail.com

# re: Function to Clone DataView with new sort column(s)

Left by Thankful at 8/31/2008 3:12 AM
Gravatar
It helped me. Thanks for the code.

Your comment:



 (will not be displayed)


 
 
 
Please add 7 and 5 and type the answer here:
 

Live Comment Preview:

 
«October»
SunMonTueWedThuFriSat
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678