我有一个带有一些可编程排序列的datagridview,排序本身是在鼠标点击时完成的。我可以获得gliph方向属性但不显示字形。
知道为什么吗?
private void gvRules_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
var column = gvRules.Columns[e.ColumnIndex];
var sortGlyphDirection = column.HeaderCell.SortGlyphDirection;
if (column.SortMode != DataGridViewColumnSortMode.Programmatic)
return;
switch (sortGlyphDirection)
{
case System.Windows.Forms.SortOrder.None:
case System.Windows.Forms.SortOrder.Ascending:
gvRules.Sort(column, ListSortDirection.Ascending);
break;
case System.Windows.Forms.SortOrder.Descending:
gvRules.Sort(column, ListSortDirection.Descending);
break;
default:
break;
}
}
答案 0 :(得分:2)
private void gvRules_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
// Put each of the columns into programmatic sort mode.
foreach (DataGridViewColumn column in ((DataGridView)sender).Columns)
{
column.SortMode = DataGridViewColumnSortMode.Programmatic;
}
}
需要再次设置column.SortMode编程
答案 1 :(得分:0)
您必须在设置GridView数据源之后设置SortGlyphDirection