【问题标题】:Cannot get value for first column on a selected row in listview无法获取列表视图中选定行的第一列的值
【发布时间】:2014-12-12 00:23:28
【问题描述】:

我正在尝试获取用户在我的 WPF 应用程序中找到的列表视图中双击的选定行上第一列的值。不幸的是,我不断收到以下错误消息:

Additional information: Unable to cast object of type 'PlotList' to type 'System.Windows.Controls.ListViewItem'.

知道如何解决这个问题吗?到目前为止,这是我的代码:

    private void PlotListView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
    {
        var lvi = (ListViewItem)PlotListView.SelectedItems[0];
        MessageBox.Show(lvi.ToString());
    }

【问题讨论】:

  • PlotListView绑定了什么类型的数据?
  • @Sam 错误状态 PlotList

标签: c# wpf listview


【解决方案1】:

试试这个:

MessageBox.Show(PlotListView.SelectedItems[0].SubItems[0].Text);

【讨论】:

  • 我认为第一个子项是第二列
【解决方案2】:

ListView.SelectedItems返回你添加到ListView.Items的对象。它不能转换成ListViewItem。ListViewItem是ListView中item的容器。 从它的继承层次中,我们可以发现它是一个Control

【讨论】:

    猜你喜欢
    • 2015-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-23
    • 2017-04-18
    • 1970-01-01
    • 2015-02-15
    • 2014-10-04
    相关资源
    最近更新 更多