c# - 字形未显示在 datagridview 上

标签 c# winforms datagridview

我有一个带有一些可编程排序列的数据 GridView ,排序本身是通过鼠标单击完成的。我可以获得字形方向属性,但没有显示字形。

知道为什么吗?

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;
  }
}

最佳答案

找到了:

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 程序

关于c# - 字形未显示在 datagridview 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8396331/

相关文章:

c# - 网络机器上的 FileSystemWatcher 设置凭据

C#、WinForms : Why isn't OnPaintBackground called when I call Refresh()?

windows - Windows 窗体中的 ComboBox Datagridview 控件

c# - 如何使用 LINQ 获取集合中的第二个元素?

c# - 如何在 closedXml c# 中禁用自动过滤器?

windows - 如何自动化 "Windows Security"窗口: "Windows can' t verify the publisher of this driver software"

c# - 阻止 DataGridView 在面板下流动?

c# - 在 Datagridview 中使用向下箭头选择组合框项目

c# - datagridview 中的日历列 c#

c# - WPF Multibinding RelativeSource Findancestor 评估性能