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: Checkbox and Image in the same column

Hi,

I'm a new user of GridGroupingControl.

I created my own GridGroupingControl based on your GGC.
My custom GridGroupingControl looks like the ListView control and it is used by the other members of the team.

I would like to have a CheckBox column and be able to have an image near the checkboxes (in the same column).
This image is defined when the row is added in the DataTable and can be different for the all the rows.

Could you help me,
Thank you,

3 Replies

HA haneefm Syncfusion Team July 19, 2007 03:42 PM UTC

Hi Vivien,

You could get this problem of adding the image in checkbox cell by handling the TableControlDrawCell event in grid. Please add this event handler in a form's event and use the following code.

ImageList list;

void gridGroupingControl1_TableControlDrawCell(object sender, GridTableControlDrawCellEventArgs e)
{
if (e.Inner.Style.CellType == "CheckBox")
{
e.Inner.Cancel = true;
Rectangle rect = e.Inner.Bounds;
rect.Width = e.Inner.Bounds.Width / 2;
e.Inner.Renderer.Draw(e.Inner.Graphics, rect, e.Inner.RowIndex, e.Inner.ColIndex, e.Inner.Style);
rect.Offset(e.Inner.Bounds.Width/2,0);
e.Inner.Graphics.DrawImage(list.Images[e.Inner.RowIndex%list.Images.Count], rect);
}
}

Best regards,
Haneef


VI Vivien July 20, 2007 09:49 AM UTC

Hi Haneef,

Thank you for your answer!
I have a function which add a new row in my datatable and this one is called when the user presses a button for example.
In this function, I would like to add a specific image, for example the image of index 1 in my imagelist, just for this new row and for my specific checkbox column.
Is it possible to draw an image at this time?

/// Inserts a row at a specified index.
/// The specified index.
private void InsertRow(int rowIndex)
{
int imageIndex = 1; // To be calculated

// Create the new row with the icon
DataRow row = dataTable.NewRow();
row.ItemArray = new object[] { true, "row inserted" };
dataTable.Rows.InsertAt(row, rowIndex);

//myGridGroupingControl.SetImageForRow(rowIndex, checkBoxColIndex, imageIndex); // TODO
}

Please advice again,
Thank you



HA haneefm Syncfusion Team July 20, 2007 05:08 PM UTC

Hi Vivien,

The best way to do this would be to have an extra column in your DataTable say ‘ImageIndex’ to keep track of the image index of the CheckBox. You can initially set the value to be -1 and draw the image from the list to checkbox cell. So whenever you need to add a row, you just need to set the imageIndex column value of that Row field to 'Index'. This will be very faster.

void gridGroupingControl1_TableControlDrawCell(object sender, GridTableControlDrawCellEventArgs e)
{
if (e.Inner.Style.CellType == "CheckBox")
{
GridTableCellStyleInfo style = e.Innder.Style as GridTableCellStyleInfo;
Element el = style.TableCellIndentity.DisplayElement;
if( el != null && el.Kind == DisplayElementKind.Record )
{
int index = Convert.ToString(el.GetRecord().GetValue("ImageIndex"));
e.Inner.Cancel = true;
Rectangle rect = e.Inner.Bounds;
rect.Width = e.Inner.Bounds.Width / 2;
e.Inner.Renderer.Draw(e.Inner.Graphics, rect, e.Inner.RowIndex, e.Inner.ColIndex, e.Inner.Style);
rect.Offset(e.Inner.Bounds.Width/2,0);
e.Inner.Graphics.DrawImage(list.Images[index], rect);
}
}
}


Best regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon