C# WPF listview不更新

标签 c# wpf listview

列名显示在 ListView 中,但行不显示。 所以我认为这部分是正确的:

List<string[]> list = gl.ReadCSV(fileNameBox.Text);

GridView gridView = new GridView();
listViewTable.View = gridView;
foreach (string st in list.First())
{
     gridView.Columns.Add(new GridViewColumn
    {
        Header = st,
        DisplayMemberBinding = new Binding(st)
    });
}

但我认为这里缺少一些东西。或者不正确。

for (int i = 1; i < list.Count; i++)
{
    listViewTable.Items.Add(new FHInfo(list[i][0], list[i][1], list[i][2], list[i][3], list[i][4], 
                    list[i][5], list[i][6], list[i][7], list[i][8], list[i][9], list[i][10], list[i][11], list[i][12]));
}
listViewTable.Items.Refresh();

摘要: ListView 保持为空,仅显示列名称。 我的意思是,listViewTable.Items.Add(...) 添加了所有内容(我在调试时可以看到),但 GUI 中没有显示任何内容。 (仅列名称) 感谢您的帮助。

这是 FHInfo 类:

class FHInfo
{
    private string building;
    private string floor;
    private string room;
    private string roomdesc;
    private string distributor;
    private string patchpanel;
    private string socket;
    private string switchFH;
    private string lineCard;
    private string port;
    private string vlan;
    private string device;
    private string gigabitAble;

    internal string Building { get => building; set => building = value; }
    internal string Floor { get => floor; set => floor = value; }
    internal string Room { get => room; set => room = value; }
    internal string Roomdesc { get => roomdesc; set => roomdesc = value; }
    internal string Distributor { get => distributor; set => distributor = value; }
    internal string Patchpanel { get => patchpanel; set => patchpanel = value; }
    internal string Socket { get => socket; set => socket = value; }
    internal string SwitchFH { get => switchFH; set => switchFH = value; }
    internal string LineCard { get => lineCard; set => lineCard = value; }
    internal string Port { get => port; set => port = value; }
    internal string Vlan { get => vlan; set => vlan = value; }
    internal string Device { get => device; set => device = value; }
    internal string GigabitAble { get => gigabitAble; set => gigabitAble = value; }

    public FHInfo(string building, string floor, string room, string roomdesc, string distributor, string patchpanel, string socket, string switchFH, string lineCard, string port, string vlan, string device, string gigabitAble)
    {
        this.building = building;
        this.floor = floor;
        this.room = room;
        this.roomdesc = roomdesc;
        this.distributor = distributor;
        this.patchpanel = patchpanel;
        this.socket = socket;
        this.switchFH = switchFH;
        this.lineCard = lineCard;
        this.port = port;
        this.vlan = vlan;
        this.device = device;
        this.gigabitAble = gigabitAble;
    }
}

最佳答案

  1. 您需要在 FHFInfo 类中包含属性,其名称与 CSV 文件的 header 完全相同。
  2. 这些属性必须是公开的。

关于C# WPF listview不更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51532078/

相关文章:

android - 在 ListView 中搜索无法正常工作

c# - 应用程序级别的通用上下文菜单

c# - 使用 C# 的 Asp.Net 中的文本框?

c# - 从方法返回 iDisposable - 谁负责处理?

c# - WPF - 将位图转换为图像源

android listview 顺序在调用 notifyDataSetChanged 时改变

c# - 编译器错误 : Invalid rank specifier: expected' ,' or ' ]' on Two Dimensional Array Initialization

c# - 在 ListView WPF 中设置项目焦点

wpf - 将 3D 网格转换为 2D 并将其放置在 WPF Canvas 上

java - fragment 内有两列的 ListView