Skip to main content Skip to footer

Control Group Row Selection in C1TrueDBGrid

Grouping is a common feature found in most of the grids. To apply grouping in C1TrueDBGrid all we need to do is set the DataView property of C1TrueDBGrid to GroupBy. Please refer to the following link to know more about it. /componentone/docs/win/online-truedbgrid/overview.html When grouping is performed, row selection in C1TrueDBGrid behaves in the following manner :

  1. When the grid is loaded for the first time the first group header row is highlighted.
  2. The data row gets selected when the record selector is clicked.
  3. The group header row does not get selected when you expand or collapse a group.

In this blog, we'll discuss how to customize this default behavior in the following ways:

  1. When the grid is loaded for the first time the first group header row is not highlighted as the user has not selected any row yet.
  2. The group header row is selected when you expand or collapse a group.

To accomplish this, we need to set the FetchStyle property of all the columns in the grid to True, so as to raise the FetchGroupCellStyle event . Later, the same event is used to highlight the group header row depending on whether it is the selected row or not.


this.c1TrueDBGrid1.FetchGroupCellStyle += (s1, e1) =>  
 {  
   var grid = s1 as C1.Win.C1TrueDBGrid.C1TrueDBGrid;  
   if (e1.Row == 0 & start)  
   {  
      e1.CellStyle.BackColor = Color.Transparent;  
      e1.CellStyle.ForeColor = Color.Black;  
      start = false;  
   }  
   else  
   {  
     if (e1.Row == row)  
     {  
       if (grid.Splits[0].Rows[e1.Row].RowType == C1.Win.C1TrueDBGrid.RowTypeEnum.ExpandedGroupRow| grid.Splits[0].Rows[e1.Row].RowType == C1.Win.C1TrueDBGrid.RowTypeEnum.CollapsedGroupRow)  
        {  
          e1.CellStyle.BackColor = Color.Blue;  
          e1.CellStyle.ForeColor = Color.White;  
        }  
     }  
     else  
     {  
       e1.CellStyle.BackColor = Color.Transparent;  
       e1.CellStyle.ForeColor = Color.Black;  
    }  
  }  
};  


Download the following samples for complete implementation. Download Sample - VB Download Sample - C#

MESCIUS inc.

comments powered by Disqus