Last active
September 5, 2017 11:19
-
-
Save craigeddy/bd1b5f1a819ccb7f439885d82f39abd1 to your computer and use it in GitHub Desktop.
Grouping columns programmatically in the Telerik RadGridView control for WinForms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://docs.telerik.com/devtools/winforms/gridview/view-definitions/column-groups-view | |
// Grouped columns do not wrap header text; see http://www.telerik.com/forums/grouping-column-headers | |
var view = new ColumnGroupsViewDefinition(); | |
var group = new GridViewColumnGroup("Reference Data"); | |
view.ColumnGroups.Add(group); | |
var groupRow = new GridViewColumnGroupRow(); | |
group.Rows.Add(groupRow); | |
groupRow.Columns.Add(gridItems.Columns["colRecordType"]); | |
groupRow.Columns.Add(gridItems.Columns["colFundingAgency"]); | |
groupRow.Columns.Add(gridItems.Columns["colMechanismID"]); | |
groupRow.Columns.ToList().ForEach(c => c.WrapText = true); | |
group.IsPinned = true; | |
group = new GridViewColumnGroup(""); | |
view.ColumnGroups.Add(group); | |
groupRow = new GridViewColumnGroupRow(); | |
group.Rows.Add(groupRow); | |
groupRow.Columns.Add(gridItems.Columns["colMechanismName"]); | |
groupRow.Columns.Add(gridItems.Columns["colPrimePartner"]); | |
groupRow.Columns.Add(gridItems.Columns["colTBDMechanism"]); | |
groupRow.Columns.Add(gridItems.Columns["colNewMechanism"]); | |
groupRow.Columns.Add(gridItems.Columns["colWorkingCapitalFund"]); | |
groupRow.Columns.ToList().ForEach(c => c.WrapText = true); | |
group = new GridViewColumnGroup("EE"); | |
view.ColumnGroups.Add(group); | |
groupRow = new GridViewColumnGroupRow(); | |
group.Rows.Add(groupRow); | |
groupRow.Columns.Add(gridItems.Columns["colGHP_State"]); | |
groupRow.Columns.ToList().ForEach(c => c.WrapText = true); | |
group = new GridViewColumnGroup("DD"); | |
view.ColumnGroups.Add(group); | |
groupRow = new GridViewColumnGroupRow(); | |
group.Rows.Add(groupRow); | |
groupRow.Columns.Add(gridItems.Columns["colGHP_USAID"]); | |
groupRow.Columns.ToList().ForEach(c => c.WrapText = true); | |
gridItems.ViewDefinition = view; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that newer versions of the RadGridView support design-time column groupings.