【问题标题】:updating the listview subitem text after an event事件后更新列表视图子项文本
【发布时间】:2014-12-08 10:47:57
【问题描述】:

我有可能会更改事件文本的列表视图,如下所示:

    private void OnEvent(object sender, AutomateConnectionEventArgs e)
    {
        if (aListView.InvokeRequired)
        {
            Invoke(new MethodInvoker(delegate()
            {
                Traitement(e);
            }));
        }
        else
        {
            Traitement(e); 
        }
    }


    private void Traitement(AutomateConnectionEventArgs e)
    {
        ListViewItem item = aListView.FindItemWithText(e.idAutomate);
        if (e.notification.Equals("connect"))
        {
            aListView.Items[item.index].SubItems[5].Text = DateTime.Today.ToShortDateString();

            aListView.Items[item.index].SubItems[7].ForeColor = Color.Green;
            aListView.Items[item.index].SubItems[7].Text = "Connected";
            aListView.Items[item.index].SubItems[8].Text = DateTime.Now.ToLongTimeString();
        }
    }

没有错误,当在 Visual Studio 中使用断点执行此操作时,它运行正确,但列表视图不会更改表单中的文本

【问题讨论】:

  • 很可能您正在更新不同的实例。在Traitement 中添加this.Show()(假设这里指的是Form),看看是否有新的表单显示出来。

标签: c# winforms listview


【解决方案1】:

只需使用新值创建新的ListViewItem 对象并使用新的 ListViewItem 对象更新旧的ListeviewItem

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-21
    • 1970-01-01
    • 2019-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多