字形不显示在datagridview上

时间:2011-12-06 06:55:52

标签: c# winforms datagridview

我有一个带有一些可编程排序列的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;
  }
}

2 个答案:

答案 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