Skip to main content

Posts

Showing posts with the label datagrid

Merging columns in GridView/DataGrid header

As necessity to show header columns in a few rows occurs fairly often it would be good to have such functionality in the GridView/DataGrid control as an in-built feature. But meanwhile everyone solves this problem in his own way. The described below variant of the merging implementation is based on irwansyah 's idea to use the SetRenderMethodDelegate method for custom rendering of grid columns header. I guess this approach can be simplified in order to get more compact and handy code for reuse. The code overview As it may be required to merge a few groups of columns - for example, 1,2 and 4,5,6 - we need a class to store common information about all united columns. [Serializable] private class MergedColumnsInfo { // indexes of merged columns public List<int> MergedColumns = new List<int>(); // key-value pairs: key = the first column index, value = number of the merged columns public Hashtable StartColumns = new Hashtable(); // key-value pairs: ke...