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.
Unfortunately, activation email could not send to your email. Please try again.

GGC: Checkbox and Image in the same column

Thread ID:

Created:

Updated:

Platform:

Replies:

64398 Jul 19,2007 11:22 AM Jul 20,2007 01:08 PM Windows Forms 3
loading
Tags: GridControl
Vivien
Asked On July 19, 2007 11:22 AM

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,

haneefm [Syncfusion]
Replied On July 19, 2007 11:42 AM

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

Vivien
Replied On July 20, 2007 05:49 AM

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


haneefm [Syncfusion]
Replied On July 20, 2007 01:08 PM

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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;