How to display grouped data in a DataGridView?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
hi, please what is the mai function or how do i use this code? Thank you
[font=新宋体]public[/font][font=新宋体]class GroupByGrid :DataGridView[/font]​
[font=新宋体] {[/font]​
[font=新宋体] [/font]​
[font=新宋体] protected overridevoid OnCellFormatting([/font]​
[font=新宋体] DataGridViewCellFormattingEventArgs args)[/font]​
[font=新宋体] {[/font]​
[font=新宋体] // Call home to base[/font]​
[font=新宋体] base.OnCellFormatting(args);[/font]​
[font=新宋体] [/font]​
[font=新宋体] // First row always displays[/font]​
[font=新宋体] if (args.RowIndex == 0)[/font]​
[font=新宋体] return;[/font]​
[font=新宋体] [/font]​
[font=新宋体] [/font]​
[font=新宋体] if (IsRepeatedCellValue(args.RowIndex, args.ColumnIndex))[/font]​
[font=新宋体] {[/font]​
[font=新宋体] args.Value = string.Empty;[/font]​
[font=新宋体] args.FormattingApplied =true;[/font]​
[font=新宋体] }[/font]​
[font=新宋体] }[/font]​
[font=新宋体] [/font]​
[font=新宋体] private bool IsRepeatedCellValue(int rowIndex,int colIndex)[/font]​
[font=新宋体] {[/font]​
[font=新宋体] DataGridViewCell currCell =[/font]​
[font=新宋体] Rows[rowIndex].Cells[colIndex];[/font]​
[font=新宋体] DataGridViewCell prevCell =[/font]​
[font=新宋体] Rows[rowIndex - 1].Cells[colIndex];[/font]​
[font=新宋体] [/font]​
[font=新宋体] if ((currCell.Value == prevCell.Value) ||[/font]​
[font=新宋体] (currCell.Value != null && prevCell.Value !=null &&[/font]​
[font=新宋体] currCell.Value.ToString() == prevCell.Value.ToString()))[/font]​
[font=新宋体] {[/font]​
[font=新宋体] return true;[/font]​
[font=新宋体] }[/font]​
[font=新宋体] else[/font]​
[font=新宋体] {[/font]​
[font=新宋体] return false;[/font]​
[font=新宋体] }[/font]​
[font=新宋体] }[/font]​
[font=新宋体] [/font]​
[font=新宋体] protected overridevoid OnCellPainting([/font]​
[font=新宋体] DataGridViewCellPaintingEventArgs args)[/font]​
[font=新宋体] {[/font]​
[font=新宋体] base.OnCellPainting(args);[/font]​
[font=新宋体] [/font]​
[font=新宋体] args.AdvancedBorderStyle.Bottom =[/font]​
[font=新宋体] DataGridViewAdvancedCellBorderStyle.None;[/font]​
[font=新宋体] [/font]​
[font=新宋体] // Ignore column and row headers and first row[/font]​
[font=新宋体] if (args.RowIndex < 1 || args.ColumnIndex < 0)[/font]​
[font=新宋体] return;[/font]​
[font=新宋体] [/font]​
[font=新宋体] if (IsRepeatedCellValue(args.RowIndex, args.ColumnIndex))[/font]​
[font=新宋体] {[/font]​
[font=新宋体] args.AdvancedBorderStyle.Top =[/font]​
[font=新宋体] DataGridViewAdvancedCellBorderStyle.None;[/font]​
[font=新宋体] }[/font]​
[font=新宋体] else[/font]​
[font=新宋体] {[/font]​
[font=新宋体] args.AdvancedBorderStyle.Top = AdvancedCellBorderStyle.Top;[/font]​
[font=新宋体] }[/font]​
[font=新宋体] }[/font]​
[font=新宋体] }[/font]​

View the full article
 
Back
Top