Row / Column Totals
I am adding row/column totals to a regular grid using the below text. Is there a better way to *shade* them? The reason why I ask is I will later need to wipe out the entire grid, and recreate row/column totals - which could very well be a completely different row/column. I need a way to remove the shading (currently using a style) on the current *last* row/column, redraw the entire grid, then re-apply the shading to the *new* last row/column. Suggestions?
Here''s the current code for shading - though I haven''t begun the code to unshade the current row/column, only to apply that shading to the new last row/column:
// 5. Add Column Totals
if (HAS_COL_TOTAL)
{
gridControlConfMatrix[0,cols].Text = "Totals";
// gridControlConfMatrix.ColStyles[cols].CellType = "Header";
// gridControlConfMatrix.ColStyles[cols].BaseStyle = "Heading";
// gridControlConfMatrix.ColStyles[cols].Font.Bold = true;
gridControlConfMatrix.ColStyles[cols].BaseStyle = "Row Header";
for (int i = 0; i < this.numRows; i++)
{
int nColTotal = 0;
for (int j = 0; j < this.numCols; j++)
nColTotal += this.intArray[i+1,j+1];
gridControlConfMatrix[i+1,cols].CellValue = nColTotal;
// gridControlConfMatrix[i+1,cols].BackColor = Color.FromArgb(208,208,208);
}
}
// 6. Add Row Totals
if (HAS_ROW_TOTAL)
{
gridControlConfMatrix[rows,0].Text = "Totals";
// gridControlConfMatrix.RowStyles[rows].CellType = "Header";
// gridControlConfMatrix.RowStyles[rows].BaseStyle = "Heading";
// gridControlConfMatrix.RowStyles[rows].Font.Bold = true;
gridControlConfMatrix.RowStyles[rows].BaseStyle = "Column Header";
for (int i = 0; i < this.numCols; i++)
{
int nRowTotal = 0;
for (int j = 0; j < this.numRows; j++)
nRowTotal += this.intArray[j+1,i+1];
gridControlConfMatrix[rows,i+1].CellValue = nRowTotal;
// gridControlConfMatrix[rows,i+1].BackColor = Color.FromArgb(208,208,208);
}
}
SIGN IN To post a reply.
4 Replies
MS
Michael Scott
November 29, 2005 09:24 PM UTC
BTW, I''m still trying to find the best way to force the row/column total NOT have a gradient shading pattern, as the row/column borders do (at least on my machine).
AD
Administrator
Syncfusion Team
November 30, 2005 12:36 AM UTC
To set the last row/column to be a special color (no matter where the last row/column is), you can use the PrepareViewStyleInfo event.
private void gridControl1_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
{
if(e.RowIndex == this.gridControl1.RowCount && e.ColIndex > 0)
{
e.Style.BackColor = Color.Red;
e.Style.CellType = "Static";
}
else if(e.ColIndex == this.gridControl1.ColCount && e.RowIndex > 0)
{
e.Style.BackColor = Color.Red;
e.Style.CellType = "Static";
}
}
The reason you are getting the gradient colors is because you are setting the CellType to "Header". The above code uses a Static celltype instead.
MS
Michael Scott
November 30, 2005 12:41 AM UTC
I''ll give that a shot, but what I''m looking for is to have this last row/column *look* similar to a row/col border.
I also need to have the entire row / col selected by clicking the last cell in that row/column - and act as if I''d clicked on the border instead. Possible?
AD
Administrator
Syncfusion Team
November 30, 2005 12:52 AM UTC
You want the last row and column to look like a header but not have the header shading used by the grid''s default header. If so, try using the static celltype but also try setting e.Style.CellAppearance = GridCellAppearance.Raised;
To handle selecting cells when you click a particular cell, try handling the CellClick event. In the handler, call grid.Selections.SelectRange to select th erange you want to select.
SIGN IN To post a reply.
- 4 Replies
- 2 Participants
-
MS Michael Scott
- Nov 29, 2005 09:23 PM UTC
- Nov 30, 2005 12:52 AM UTC