blood1999

Hi, does any one if I can customize the Sort Glyph in DataGridView Column header, for example, change the color of Sort Glyph or paint my own Sort Glyph image.

Thanks a lot.



Re: Windows Forms Data Controls and Databinding Customize Sort Glyph

Naga Satish Rupenaguntla

the following link might be useful

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=217442&SiteID=1






Re: Windows Forms Data Controls and Databinding Customize Sort Glyph

Yu Guo – MSFT

Hi, blood1999,

I wrote a small sample to illustrate how to draw your own Sort Glyph image on the DataGridView Header Cell

Code Snippet

private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)

{

if (e.RowIndex == -1 && e.ColumnIndex >= 0 && dataGridView1.Columns[e.ColumnIndex].HeaderCell.SortGlyphDirection != SortOrder.None)

{

Image image = null;

if (dataGridView1.Columns[e.ColumnIndex].HeaderCell.SortGlyphDirection == SortOrder.Ascending)

{

image = Image.FromFile(@"D:\asc.gif");

}

else if (dataGridView1.Columns[e.ColumnIndex].HeaderCell.SortGlyphDirection == SortOrder.Descending)

{

image = Image.FromFile(@"D:\des.gif");

}

SolidBrush brush = new SolidBrush(Color.FromKnownColor(KnownColor.Control));

e.Graphics.FillRectangle(brush, e.CellBounds);

e.Paint(e.ClipBounds, (DataGridViewPaintParts.All & ~DataGridViewPaintParts.Background));

e.Graphics.DrawImage(image, new Point(e.CellBounds.X + e.CellBounds.Width - 15, e.CellBounds.Y + (e.CellBounds.Height / 2) - (image.Height / 2)));

e.Handled = true;

}

}

Hopes this helps,

Regards