Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Customizing the sortglyph in the datagridview
 

Customizing the sortglyph in the datagridview

I have implemented custom sorting in my datagridview and am setting the sortglyphdirection property. All of this works fine but the position of the sort glyph is too far to the right in my columns. I set the column width to something reasonable for the width of the data in the column and the sortglyph doesn't show because it is outside the visible width of the column. It seems that I have to set the width of the column artificially wide in order to see the glyph. Is there some way to control the placement of the glyph or to display my own arrow in the header?
Linda Call  Friday, December 19, 2008 3:18 PM
Hi Linda Call,

By default, the glyph alwaysdisplays at the right of the headCell of a column.
It's impossible to control the placement of if.
But you can handle the cellPainting event of a dataGridVew to draw the text and the arrow yourself.
privatevoiddataGridView1_CellPainting(objectsender,DataGridViewCellPaintingEventArgse)
{
if(e.ColumnIndex>-1&&e.RowIndex==-1)
{
e.Paint(e.CellBounds,DataGridViewPaintParts.All&~DataGridViewPaintParts.ContentForeground);
e.Graphics.DrawString("ASDAa",e.CellStyle.Font,newSolidBrush(e.CellStyle.ForeColor),e.CellBounds);
e.Handled=true;
}
}

If there's any problem, please feel free to let me know.

Best regards,
Steven Yu
Steven.Yu  Monday, December 22, 2008 6:13 AM
Hi Linda Call,

By default, the glyph alwaysdisplays at the right of the headCell of a column.
It's impossible to control the placement of if.
But you can handle the cellPainting event of a dataGridVew to draw the text and the arrow yourself.
privatevoiddataGridView1_CellPainting(objectsender,DataGridViewCellPaintingEventArgse)
{
if(e.ColumnIndex>-1&&e.RowIndex==-1)
{
e.Paint(e.CellBounds,DataGridViewPaintParts.All&~DataGridViewPaintParts.ContentForeground);
e.Graphics.DrawString("ASDAa",e.CellStyle.Font,newSolidBrush(e.CellStyle.ForeColor),e.CellBounds);
e.Handled=true;
}
}

If there's any problem, please feel free to let me know.

Best regards,
Steven Yu
Steven.Yu  Monday, December 22, 2008 6:13 AM

You can use google to search for other answers

Custom Search

More Threads

• How does one bind to a multiple selection ?
• Moving Things Up in a list box order - Works Sometimes then stops working
• Set BindingSource.DataSource Odd Behaviour
• datagridview
• Gridview column width
• Datagrid show few columns...
• aggregate data from a table to datagrid
• DataGridView maxes out at 140 rows
• how to do restrict char in datagridviewcell?
• Loading data into the database