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

GGCTableControlDrawCell issues

Hi,
Please find another example of my nested tables project.

The problem Im seeing now is as follows;
Expand node Table2
Expand sub node Test 1

Problem, the first node within Test 1 is drawing the icon that is drawn on Test 1.

Click on another child node of Test1.

Problem, each node clicked is also drawing the icon that is drawn on Test 1.

Im guessing that the way I detect what table is being drawn in this event is wrong? Im using e.TableControl.TableDescriptor.Name to get the name of the table being drawn which works for the first 2 levels, but not properly for the 3rd.

Any pointers would be appreciated.

Thanks

John



GGC_3_levels_example0.zip

5 Replies

AD Administrator Syncfusion Team February 7, 2007 06:03 PM UTC

Hi John,

You can use the DrawCell event of GridTableControl to achieve this.

grid.GetTableControl("NavParent").DrawCell += new GridDrawCellEventHandler(NavParent_DrawCell);
grid.GetTableControl("Table2").DrawCell += new GridDrawCellEventHandler(Table2_DrawCell);

void Table2_DrawCell(object sender, GridDrawCellEventArgs e)
{
if (e.ColIndex == 3)
{
e.Renderer.Draw(e.Graphics, e.Bounds, e.RowIndex, e.ColIndex, e.Style);
Icon failureIcon = SystemIcons.Error;
Icon warningIcon = SystemIcons.Warning;
Rectangle iRect = new Rectangle(e.Bounds.Width - 100, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height);
e.Graphics.DrawIconUnstretched(warningIcon, iRect);
iRect.X = iRect.X + 80;
e.Graphics.DrawIconUnstretched(failureIcon, iRect);
e.Cancel = true;
}
}

void NavParent_DrawCell(object sender, GridDrawCellEventArgs e)
{
if (e.ColIndex == 3)
{
e.Renderer.Draw(e.Graphics, e.Bounds, e.RowIndex, e.ColIndex, e.Style);
Icon failureIcon = SystemIcons.Error;
Icon warningIcon = SystemIcons.Warning;
Rectangle iRect = new Rectangle(e.Bounds.Width - 100, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height);
e.Graphics.DrawIconUnstretched(warningIcon, iRect);
iRect.X = iRect.X + 80;
e.Graphics.DrawIconUnstretched(failureIcon, iRect);
e.Cancel = true;
}
}

Please refer to the attached sample for modification.
GGCModified.zip

Best Regards,
Haneef


JH John H February 9, 2007 10:22 AM UTC

Hi Haneef,

In your example, Table2_DrawCell is checking e.ColIndex == 3, which is actually the expand collapse icon. Why is it that the first real column is actually at index 4?

Thanks
John

>Hi John,

You can use the DrawCell event of GridTableControl to achieve this.

grid.GetTableControl("NavParent").DrawCell += new GridDrawCellEventHandler(NavParent_DrawCell);
grid.GetTableControl("Table2").DrawCell += new GridDrawCellEventHandler(Table2_DrawCell);

void Table2_DrawCell(object sender, GridDrawCellEventArgs e)
{
if (e.ColIndex == 3)
{
e.Renderer.Draw(e.Graphics, e.Bounds, e.RowIndex, e.ColIndex, e.Style);
Icon failureIcon = SystemIcons.Error;
Icon warningIcon = SystemIcons.Warning;
Rectangle iRect = new Rectangle(e.Bounds.Width - 100, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height);
e.Graphics.DrawIconUnstretched(warningIcon, iRect);
iRect.X = iRect.X + 80;
e.Graphics.DrawIconUnstretched(failureIcon, iRect);
e.Cancel = true;
}
}

void NavParent_DrawCell(object sender, GridDrawCellEventArgs e)
{
if (e.ColIndex == 3)
{
e.Renderer.Draw(e.Graphics, e.Bounds, e.RowIndex, e.ColIndex, e.Style);
Icon failureIcon = SystemIcons.Error;
Icon warningIcon = SystemIcons.Warning;
Rectangle iRect = new Rectangle(e.Bounds.Width - 100, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height);
e.Graphics.DrawIconUnstretched(warningIcon, iRect);
iRect.X = iRect.X + 80;
e.Graphics.DrawIconUnstretched(failureIcon, iRect);
e.Cancel = true;
}
}

Please refer to the attached sample for modification.
GGCModified.zip

Best Regards,
Haneef


JH John H February 9, 2007 11:18 AM UTC

Hi Haneef,
Why is it that DrawCell events are fired for NavParent and Table2 when trying to draw the cell for Table2_2?

Why is it that in Table2_DrawCell, checking for e.ColIndex == 2 renders that child node correctly, but if you expand it, rows for Table2_2 are actually drawing the icons for NavParent? Table2_2 doesn't even have a DrawCell event, why are events for different tables firing on it?

This doesn't make any sense to me as yet, Im hoping you can shed some light on this. Im struggling to see the logic that you have applied here.

Thanks
John


JH John H February 14, 2007 11:49 AM UTC

Hi Haneef,
I still need feedback on this issue as well please.

Thanks
John

>Hi Haneef,
Why is it that DrawCell events are fired for NavParent and Table2 when trying to draw the cell for Table2_2?

Why is it that in Table2_DrawCell, checking for e.ColIndex == 2 renders that child node correctly, but if you expand it, rows for Table2_2 are actually drawing the icons for NavParent? Table2_2 doesn't even have a DrawCell event, why are events for different tables firing on it?

This doesn't make any sense to me as yet, Im hoping you can shed some light on this. Im struggling to see the logic that you have applied here.

Thanks
John


AD Administrator Syncfusion Team February 15, 2007 12:23 AM UTC

Hi John,

Why is it that DrawCell events are fired for NavParent and Table2 when trying to draw the cell for Table2_2?
>>>>
The reason is that you are drawing the inner most child node of the grid.When you draw the inner most child, the grid fisrt draws its parent and than child node.

Why is it that in Table2_DrawCell, checking for e.ColIndex == 2 renders that child node correctly, but if you expand it, rows for Table2_2 are actually drawing the icons for NavParent? Table2_2 doesn't even have a DrawCell event, why are events for different tables firing on it?
>>>>>
The ColIndex of the cell can be changed depends on the indent column and grouping column. Please try the below code find the correct column here.

void Table2_DrawCell(object sender, GridDrawCellEventArgs e)
{
GridTableControl tc = sender as GridTableControl;
int filed = tc.TableDescriptor.ColIndexToField(e.ColIndex);
string columnName = tc.TableDescriptor.VisibleColumns[filed].Name;
if (columnName == "YouColumnName")
{
//your code here....
}
}

Best regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon