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

Cell icon

i have a column, the column cells for certain rows must contain a custom icon i made....
So i want for some cells of that column to have an icon, and others to be blank...where i'm gonna put the icon is determined by the value of the row cell, that is, if the cell has value show the icon, and if it's null show nothing...

There's a rough picture in the attachment...

The black stains represent the places where to put the icon..I'm fillin that column from a database, and when the columns are filled, i want there to be an icon in the places where the value exists,and where the value is not null (in the database).

Thanx..p.s. sorry for the bad picture :)

cellIcon.zip

6 Replies

HA haneefm Syncfusion Team June 5, 2007 05:41 PM UTC

Hi Mario,

You can do this by handling the TableControlDrawCell event of the grid and draw image by using the Graphics.DrawXXX method. Below is a code snippet

void gridGroupingControl1_TableControlDrawCell(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlDrawCellEventArgs e)
{
GridTableCellStyleInfo style = e.Inner.Style as GridTableCellStyleInfo;
Element el = style.TableCellIdentity.DisplayElement;

if (el.Kind == DisplayElementKind.Record && style.TableCellIdentity.Column != null
&& style.TableCellIdentity.Column.Name == "Col 1")
{
if (style.CellValue != null || style.CellValue.ToString() != string.Empty)
{
e.Inner.Cancel = true;
e.Inner.Graphics.DrawIcon(SystemIcons.Question, e.Inner.Bounds);
}
}
}

Best regards,
Haneef


M. m.n.m,n.mn June 5, 2007 07:18 PM UTC



>Hi Mario,

You can do this by handling the TableControlDrawCell event of the grid and draw image by using the Graphics.DrawXXX method. Below is a code snippet

void gridGroupingControl1_TableControlDrawCell(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlDrawCellEventArgs e)
{
GridTableCellStyleInfo style = e.Inner.Style as GridTableCellStyleInfo;
Element el = style.TableCellIdentity.DisplayElement;

if (el.Kind == DisplayElementKind.Record && style.TableCellIdentity.Column != null
&& style.TableCellIdentity.Column.Name == "Col 1")
{
if (style.CellValue != null || style.CellValue.ToString() != string.Empty)
{
e.Inner.Cancel = true;
e.Inner.Graphics.DrawIcon(SystemIcons.Question, e.Inner.Bounds);
}
}
}

Best regards,
Haneef


Hi Haneef,
i tried your snippet, but i got the same thing where i myself stuck :), the event fill all cells no matter if there's a value, and the icon is large, it spreads through the entire cell...

Example in the attachement...



CellIcon0.zip


HA haneefm Syncfusion Team June 5, 2007 07:33 PM UTC

Hi Mario,

You can try these code snippet:

GridTableCellStyleInfo style = e.Inner.Style as GridTableCellStyleInfo;
Element el = style.TableCellIdentity.DisplayElement;

if (el.Kind == DisplayElementKind.Record && style.TableCellIdentity.Column != null && style.TableCellIdentity.Column.Name == "Stup")
{
if (style.CellValue != null && style.CellValue.ToString() != string.Empty)
{
e.Inner.Cancel = true;
e.Inner.Graphics.DrawIcon(SystemIcons.Question, e.Inner.Bounds);
}
}

Best regards,
Haneef


M. m.n.m,n.mn June 5, 2007 07:42 PM UTC



>Hi Mario,

You can try these code snippet:

GridTableCellStyleInfo style = e.Inner.Style as GridTableCellStyleInfo;
Element el = style.TableCellIdentity.DisplayElement;

if (el.Kind == DisplayElementKind.Record && style.TableCellIdentity.Column != null && style.TableCellIdentity.Column.Name == "Stup")
{
if (style.CellValue != null && style.CellValue.ToString() != string.Empty)
{
e.Inner.Cancel = true;
e.Inner.Graphics.DrawIcon(SystemIcons.Question, e.Inner.Bounds);
}
}

Best regards,
Haneef


Thanx Haneef, it's working now, but there's still the "huge" icon problem....the icon stretches itself through the cell...


HA haneefm Syncfusion Team June 5, 2007 09:41 PM UTC

Hi Mario,

You can specify the location and size of the resulting image on the display surface in DrawIcon method. Please try the below code snippet to display image at center of the gridcell and let me know if this helps.

Rectangle _rectCenter = GridUtil.CenterInRect(e.Inner.Bounds, SystemIcons.Question.Size);
e.Inner.Graphics.DrawIcon(SystemIcons.Question, _rectCenter );

Best regards,
Haneef


M. m.n.m,n.mn June 7, 2007 06:23 PM UTC



>Hi Mario,

You can specify the location and size of the resulting image on the display surface in DrawIcon method. Please try the below code snippet to display image at center of the gridcell and let me know if this helps.

Rectangle _rectCenter = GridUtil.CenterInRect(e.Inner.Bounds, SystemIcons.Question.Size);
e.Inner.Graphics.DrawIcon(SystemIcons.Question, _rectCenter );

Best regards,
Haneef


Thanx Haneef, it's working fine now..

Loader.
Live Chat Icon For mobile
Up arrow icon