The grid supports working with a single header or with multiple headers. When there is only one header, grid behavior is almost always identical to Windows explorer behavior, where data on any hierarchy level is subordinate to just a single header. Multiple headers enable setting different columns for different hierarchy levels and using different sorting, grouping, etc. To add a header to the grid you have to call Grid.Headers.Add(Header header) methods. If you call this method several times in a row, the grid will work with multiple header. Please see below examples of building a grid with a single header in Windows explorer style and a grid with multiple headers.
Copy | |
---|---|
public void SingleHeaderGrid(Grid grid) { //Initialize the grid with a single header, which has 3 columns //With a single header the grid works as tree list view grid.Headers.Add(new Header()); grid.Headers[0].Add(new Column("Name")); grid.Headers[0].Add(new Column("Size")); grid.Headers[0].Add(new Column("CreationTime", "Creation time")); //Add some folders and files to the grid Row row = grid.Rows.Add(new Folder("Windows")); row.Add(new File("ReadMe.txt")); row.Add(new File("win.ini")); } public void MultipleHeaderGrid(Grid grid) { //Initialize the grid with two headers grid.Headers.Add(new Header()); grid.Headers[0].Add(new Column("FirstName", "First Name")); grid.Headers[0].Add(new Column("LastName", "Last Name")); grid.Headers.Add(new Header()); grid.Headers[1].Add(new Column("BookName", "Name")); grid.Headers[1].Add(new Column("BookGenre", "Genre")); //Add some data objects to the grid Row row = grid.Rows.Add(new Writer("Agata", "Kristi")); row.Add(new Book("Second front", "Detective story")); row.Add(new Book("Shameful Star", "Detective story")); } |
Back to .Net Grid HowTo topics