【问题标题】:Display group header when there are no items in the group in a listview?当列表视图中的组中没有项目时显示组标题?
【发布时间】:2013-11-25 19:47:01
【问题描述】:

我想在列表视图(winform)中对我的项目进行分组,组标题显示组中的项目数(包括 0 个项目)。 我的问题是,当我从组或列表视图中清除项目时,组标题消失了。

如何确保组标题不会消失?我看不到要在 ListView 或 ListViewGroup 类中设置的任何属性。

谢谢

考虑代码:

    ListViewGroup groupA;
    ListViewGroup groupB;

    private void button1_Click(object sender, EventArgs e)
    {
        //Create group A and B and add them to the groups collection
        groupA = new ListViewGroup("A");
        listView1.Groups.Add(groupA);
        groupB = new ListViewGroup("B");
        listView1.Groups.Add(groupB);

        //Add 2 items in the list view and update the group headers
        listView1.Items.Add(new ListViewItem("Item1", groupA));
        groupA.Header = "A - 1 item";

        listView1.Items.Add(new ListViewItem("Item2", groupB));
        groupB.Header = "B - 1 item";
    }

    private void button2_Click(object sender, EventArgs e)
    {
        //Clear the items
        listView1.Items.Clear();

        //Update header
        //The problem here is that the headers are not displayed any more
        groupA.Header = "A - 0 item";
        groupB.Header = "B - 0 item";
    }

【问题讨论】:

  • 您将需要一些dummy 项目用于覆盖组。应该小心完成,让它顺利和自动地工作,我认为你需要相当多的自定义代码(几乎与某些事件相关)。

标签: c# .net winforms


【解决方案1】:

我正在回答我自己的问题!用普通的 ListView 似乎不可能做到这一点。我还查看了没有成功的底层 Win32 消息。最后还是放弃了,买了个第三方控件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多