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;
        }

Advertisements