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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Image in header

Thread ID:

Created:

Updated:

Platform:

Replies:

48719 Sep 4,2006 02:38 AM UTC Sep 5,2006 06:22 AM UTC WinForms 4
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On September 4, 2006 02:38 AM UTC

hi!

I would like to add a image in a GridControl header as shown in the attached file.

Please help!

Thanks!

ImageInHeader.zip

Administrator [Syncfusion]
Replied On September 4, 2006 04:11 AM UTC

Hi lim,

To put the Icon in the columnHeader from the ImageList, you will have to make the CellType as static or as a TextBox Cell and then set your ImageIndex. Please refer the below KB Article which describes about this.

http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=23

Let me know if you need further assistance.

Regards,
Haneef

Administrator [Syncfusion]
Replied On September 4, 2006 09:14 AM UTC

hi!

it''s working, but the image is placed before the header text.. What i expected is after the header text as shown in the attched file in my first post.

Thanks!

Administrator [Syncfusion]
Replied On September 4, 2006 11:56 AM UTC

Hi Lim,

You can handle the DrawCell event to draw the image in a column header cell and set e.Cancel = true to handle it. See the below code snippet for more details.

//Draw Cell event.
if(e.Style.CellType == "ColumnHeader" )
{
e.Style.CellAppearance = GridCellAppearance.Raised;
if(e.ColIndex == 3)
{
string s = e.Style.Text;

e.Style.ImageList = imageList1;
e.Style.ImageIndex = 1;
e.Style.Text=" ";

//Draw the ColumnHeader cell in a Grid.
Rectangle crect = new Rectangle( e.Bounds.Location,new Size( e.Bounds.Size.Width - e.Style.ImageList.ImageSize.Width,e.Bounds.Height) );
e.Renderer.Draw(e.Graphics,e.Bounds,e.RowIndex,e.ColIndex,e.Style);

//Draw the text in a Grid.
Rectangle irect = new Rectangle( new Point( e.Bounds.Right - e.Style.ImageList.ImageSize.Width , e.Bounds.Top + 2),e.Style.ImageList.ImageSize);
e.Graphics.DrawString(s,e.Style.Font.GdipFont,new SolidBrush(e.Style.TextColor),crect);

//Draw the image in a Grid.
e.Graphics.DrawImage(e.Style.ImageList.Images[0],irect);
e.Style.Text= s;

//to cancel the default drawing in a grid
e.Cancel = true;
}
}

Thanks,
Haneef

Administrator [Syncfusion]
Replied On September 5, 2006 06:22 AM UTC

Hi! It''s Working!!

Thanks a lot! :)

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.

Warning Icon 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.Close Icon

;