We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

ggc custom row color

Hi everybody,

I wish to determine ggc row-color on the fly.

so far I tried the following events:
- "myGGC_TableControlDrawCellBackground"
- "myGGC_TableControlDrawCell"
- "myGGC_TableControlCellDrawn"

It appears that they only take effect when I select a specific cell.

What is the correct approach to handle the OnPaint of each cell ?


Thanks in advance.

5 Replies

AD Administrator Syncfusion Team February 27, 2007 10:15 PM UTC

Hi Ryan

In a GridGroupingControl, you cannot set any row specific or cell specific properties like backcolor. To do this, you will have to catch the TableControlPrepareViewStyleInfo event (or QueryCellStyleInfo event). In the event handler code, you can check for the e. TableCellIdentity .RowIndex and if that points to the row you wanted, set the e.Style.BackColor to the color you want.

void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
if (e.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell || e.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell)
{
//Apply colours row wise.
if (e.TableCellIdentity.RowIndex % 2 == 0)
{
e.Style.BackColor = Color.Pink;
}

//Color for particular cell alone
if (e.TableCellIdentity.ColIndex == 1)
{
Element el = e.TableCellIdentity.DisplayElement;
if (el != null && el.Kind == DisplayElementKind.Record)
{
Record r = el.GetRecord();
object value = r.GetValue("sno");
int s = (int)value;
if (s == 3)
e.Style.BackColor = Color.Blue;
}


}
}
}

Please try the attached sample and let me know if this helps.

sample:
CustomColor.zip

Best Regards,
S.Shyam.



AD Administrator Syncfusion Team February 28, 2007 09:38 AM UTC

Hi Shyam, and thanks.

The sample application works just fine, but it's not enough for what we need.

We wish to define alternating colors to row-groups of undetermined lengths and a different color for a selected group (see the attachment).

The problem is that when I select a row, only the selected row and the previously selected row are repainted and the rest are repainted only on invalidation (e.g. when the window is hidden and then shown again).

What do I need to do in order to invalidate the other rows ?


GroupSelection.zip


AD Administrator Syncfusion Team February 28, 2007 09:44 AM UTC

Another question regarding the attachment.

The CheckBoxes are only relevant to the header rows. is there a way to make the others disappeare ?


AD Administrator Syncfusion Team February 28, 2007 11:36 AM UTC

Another interesting note that might help to pin point the problem.

The invalidation works just fine when I enter a cell's "edit" mode, but it's not complete when I select a "read-only" cell.


AD Administrator Syncfusion Team February 28, 2007 11:49 PM UTC

Hi Ryan,

Question 1) "Invalidate rows"

You can try calling the Invalidate OR refresh method to refresh all rows in a grid. Below is a code snippet

this.gridGroupingControl1.Invalidate()

Question 2) "RowHeader CheckBox"

The attached sample describes you "How to add the checkbox in a RowHeader of the GroupingGrid?". It disappears the record row when the rowheader check box value is unchecked. Here is a code snippet to show this.

Hashtable GroupCheckValue = new Hashtable();
if (GroupCheckValue.Contains(e.TableCellIdentity.RowIndex) && GroupCheckValue[e.TableCellIdentity.RowIndex].ToString() == "1")
{
e.Style.Enabled = false;
e.Style.BackColor = Color.Beige;
}
else
{
e.Style.Enabled = true;
e.Style.BackColor = Color.White;
}
sample: CheckBoxRowHeader.zip

Best Regards,
S.Shyam.

Loader.
Live Chat Icon For mobile
Up arrow icon