I have a Devexpress Xtragrid, with in which I grouped rows based on a particular column. I have given Dark blue back color to the Group and set ShowGroupExpandCollpaseButton as false as well. In the left most part of each child rows in the grid is displaying the color I set to the Group back color. Is there any way to remove this color?
Asked
Active
Viewed 1,886 times
0
-
1That is the Group Column right? – Bit Apr 27 '13 at 10:49
-
yes, is there any limitation to hide it? – 17CrazyBrain Apr 28 '13 at 05:34
3 Answers
1
To accomplish this task, please remove the BackColor
from the GroupRow appearance.
Then use the CustomDrawGroupRow event to highlight the group row content as you need:
// 1) remove GroupRow style
//gridView1.Appearance.GroupRow.BackColor = Color.Blue;
gridView1.OptionsView.ShowGroupExpandCollapseButtons = false;
// 2) use the CusomDrawGroupRow
gridView1.CustomDrawGroupRow += gridView1_CustomDrawGroupRow;
}
void gridView1_CustomDrawGroupRow(object sender, RowObjectCustomDrawEventArgs e) {
GridView gridView = sender as GridView;
GridGroupRowInfo groupRowInfo = e.Info as GridGroupRowInfo;
string groupRowText = gridView.GetGroupRowDisplayText(e.RowHandle);
int textStart = groupRowInfo.DataBounds.Left + 4;
Rectangle groupRowTextBounds = new Rectangle(
textStart,
groupRowInfo.Bounds.Top,
groupRowInfo.Bounds.Right - textStart,
groupRowInfo.Bounds.Height
);
e.Cache.FillRectangle(Brushes.Blue, e.Bounds); // draw blue backgrownd
e.Appearance.DrawString(e.Cache, groupRowText, groupRowTextBounds);
e.Handled = true;
}

DmitryG
- 17,677
- 1
- 30
- 53
-
Thank you for the solution. It is working. Now, if we group, the grid is leaving some extra space at the beginning of each child row. Is there any way to remove this?. Can you suggest some solution? – 17CrazyBrain Apr 29 '13 at 05:03
-
@17CrazyBrain Specify [level indent](http://documentation.devexpress.com/#WindowsForms/DevExpressXtraGridViewsGridGridView_LevelIndenttopic) as follows: `gridView1.LevelIndent = 0;` – DmitryG Apr 29 '13 at 06:55
0
You should be able to hide the group from the view by setting as follows:
this.gridView1.OptionsView.ShowGroupedColumns = false;

Bit
- 1,068
- 1
- 11
- 20
0
Download the [project][1](https://drive.google.com/file/d/13XkT9qsqwFP-f2sPID70T2y2fSrs4Gp0/view?usp=sharing) or follow the below steps.
Getdata
private DataTable getTestData() { ///Step 1: Getdata from Db DataTable dt = new DataTable(); dt.Columns.Add("GROUPCOLUMN"); dt.Columns.Add("PRODUCTGROUPID"); dt.Columns.Add("SIZEID"); dt.Columns.Add("SHAPEID"); dt.Columns.Add("COLORID"); dt.Columns.Add("CLARITYID"); dt.Columns.Add("CARAT", typeof(decimal)); dt.Columns.Add("QTY", typeof(Int32)); dt.Columns.Add("GROUPLEVEL", typeof(Int32)); dt.Columns.Add("AVGCARAT", typeof(decimal)); dt.Rows.Add("", "POLISH", "0.30-0.39", "BR", "D", "IF", 0.30, 1, 0, 0.30); dt.Rows.Add("", "POLISH", "0.40-0.49", "BR", "D", "IF", 0.40, 1, 0, 0.30); dt.Rows.Add("", "POLISH", "0.40-0.49", "BR", "D", "VVS1", 0.40, 1, 0, 0.30); dt.Rows.Add("", "POLISH", "0.30-0.39", "BR", "D", "VVS2", 0.30, 1, 0, 0.30); dt.Rows.Add("", "S.PRECIOUS", "0.30-0.39", "BR", "D", "IF", 0.30, 1, 0, 0.30); dt.Rows.Add("", "S.PRECIOUS", "0.30-0.39", "BR", "D", "IF", 0.30, 1, 0, 0.30); dt.Rows.Add("", "COLOR", "0.30-0.39", "BR", "D", "IF", 0.30, 1, 0, 0.30); dt.Rows.Add("", "COLOR", "0.30-0.39", "BR", "D", "IF", 0.30, 1, 0, 0.30); return dt; }
Create GridView Event (gridView1_GroupLevelStyle) for displaying grid data color
private void gridView1_GroupLevelStyle(object sender, GroupLevelStyleEventArgs e) { ///Step 2: Create GridView Event (gridView1_GroupLevelStyle) for displaying grid data color e.LevelAppearance.ForeColor = getForeGroupColor(e.Level); e.LevelAppearance.BackColor = getBackGroupColor(e.Level); }
Create method getBackGroupColor(Group Index), getForeGroupColor(GroupIndex) in C# Code
public Color getBackGroupColor(Int32 groupLevel) { Color groupColor = Color.White; if (groupLevel == 0) { groupColor = Color.Salmon; } else if (groupLevel == 1) { groupColor = Color.Green; }}
Most Important Create Gridview Event (gridView1_CustomSummaryCalculate) and set group level into the GroupLevel Column SummaryItem(Follow the instruction as given the comment on to the method)
///Step 4: Most Important Create Gridview Event (gridView1_CustomSummaryCalculate) and set group level into the GroupLevel Column SummaryItem(Follow the instruction as given the comment on to the method) private void gridView1_CustomSummaryCalculate(object sender, DevExpress.Data.CustomSummaryEventArgs e) { if (e.IsGroupSummary) { switch (e.SummaryProcess) { case CustomSummaryProcess.Start: break; case CustomSummaryProcess.Calculate: break; case CustomSummaryProcess.Finalize: if (((DevExpress.XtraGrid.GridSummaryItem)e.Item).FieldName == "GROUPLEVEL") { ///set Group level into the grouplevel summary e.TotalValue = e.GroupLevel; } break; } } }
Create button for export grid data and write code as writen into the method Like
try { SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "Excel Workbook|*.xlsx|Excel 97-2003 Workbook|*.xls"; saveFileDialog1.Title = "Save an Excel File"; saveFileDialog1.FileName = String.Format("Test_{0}.xlsx", DateTime.Now.ToString("ddMMMyyyyhhmmss")); DialogResult res = saveFileDialog1.ShowDialog(); if (res == DialogResult.Cancel) return; XlsxExportOptionsEx exportOptions = new XlsxExportOptionsEx(); exportOptions.CustomizeCell += exportOptions_CustomizeCell; this.gridView1.ExportToXlsx(saveFileDialog1.FileName, exportOptions); System.Diagnostics.Process.Start(saveFileDialog1.FileName); } catch (Exception ex) { }
Create Method(Event) exportOptions_CustomizeCell
private void exportOptions_CustomizeCell(CustomizeCellEventArgs e) { if (e.RowHandle < 0) { ///Export excel set Group color DevExpress.XtraGrid.GridGroupSummaryItem SummaryItem = this.gridView1.GroupSummary.Where(x => x.FieldName == "GROUPLEVEL").ToList()[0] as DevExpress.XtraGrid.GridGroupSummaryItem; Int32 groupLevel = Convert.ToInt32(this.gridView1.GetGroupSummaryValue(e.RowHandle, SummaryItem)); e.Formatting.BackColor = getBackGroupColor(groupLevel); } ///Set Header Column setting(BackColor, ForeColor, Font Style) else if (e.DataSourceRowIndex == -1) { e.Formatting.BackColor = Color.Black; e.Formatting.Font.Color = Color.White; e.Formatting.Font.Italic = true; } e.Handled = true; }

Manish Dangar
- 51
- 1
- 5