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.

Image in header

Thread ID:

Created:

Updated:

Platform:

Replies:

48719 Sep 3,2006 10:38 PM Sep 5,2006 02:22 AM Windows Forms 4
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On September 3, 2006 10:38 PM

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 12:11 AM

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 05:14 AM

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 07:56 AM

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 02:22 AM

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.

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.

;