Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将Listview行的内容捕获为变量_C#_Wpf_Listview_Variables - Fatal编程技术网

C# 将Listview行的内容捕获为变量

C# 将Listview行的内容捕获为变量,c#,wpf,listview,variables,C#,Wpf,Listview,Variables,C WPF 我有一个包含3列的列表视图。我想做的是,当我双击一行时,它将捕获所选行的列的值,并将它们存储为变量,这样我就可以将它们传递到另一个页面,或者根据需要简单地操作它们。我这里有我的练习代码。现在,我只是填充一个消息框,看看是否可以正确地输出变量。现在发生的事情是,它没有从争吵中攫取任何东西。通过删除if块,我发现字符串name=selectedObject.ilName;是空的。我还有一个问题是关于ingListLV.SelectedItems[0]作为InventoryList[0]的

C WPF 我有一个包含3列的列表视图。我想做的是,当我双击一行时,它将捕获所选行的列的值,并将它们存储为变量,这样我就可以将它们传递到另一个页面,或者根据需要简单地操作它们。我这里有我的练习代码。现在,我只是填充一个消息框,看看是否可以正确地输出变量。现在发生的事情是,它没有从争吵中攫取任何东西。通过删除if块,我发现字符串name=selectedObject.ilName;是空的。我还有一个问题是关于ingListLV.SelectedItems[0]作为InventoryList[0]的语句,它具体指的是什么?我最初认为它引用了它返回的值,因此[0]将是第1列中的值,[1]将是第2列等,但我知道这是错误的

这是我的XAML

编辑 这里是我将数据加载到listview的地方

    private void LoadLV()
    {

        auroraDataEntities = new AuroraDataEntities();
        ObjectQuery<Inventory> inventories = auroraDataEntities.Inventories;
        //Returns only opjects with a quantity greater than 0, so it won't show anything you are out of
        var fillList = from q in inventories
                       where q.Qty > 0
                       select q;
        ingListLV.ItemsSource = fillList.ToList();
     }
在默认情况下不使用的单个中


[0]指的是多重选择中的第一个选定项目行。

因此在我的xaml中,我设置SelectionMode=Single。并进行了您在上面代码中选择的更改。它仍然填充为空。当我逐步浏览代码时,我注意到iList没有填充任何内容,因此看起来它从listview中获取值仍然存在问题。什么是iList?我希望这是DataContext中的列表,因为您的ItemsSource已绑定到DataContext中的对象。在ListView中看到行了吗?如果可以,请选择一个项目/行?iList在类InventoryList中声明。是的,我可以在ListView中看到行,是的,我可以在ListView中双击并启动open_edit方法,但它没有从您发布的类InventoryList中的ListView中提取值,我没有看到iList。请显示设置DataContext的代码,特别是对象的类型。对不起,是指ilName,不是ilLIst。一切都开始看起来一样了lol。我将编辑帖子以显示我将数据加载到listview的位置
    private void Open_Edit(object sender, RoutedEventArgs e)
    {
    var selectedObject = ingListLV.SelectedItems[0] as InventoryList;
    if (selectedObject == null)
    {
        return;
    }
    string name = selectedObject.ilName;
    MessageBox.Show(name);
    }

public class InventoryList
{
    public string ilName { get; set; }
    public decimal ilQty { get; set; }
    public string ilType { get; set; }
}
    private void LoadLV()
    {

        auroraDataEntities = new AuroraDataEntities();
        ObjectQuery<Inventory> inventories = auroraDataEntities.Inventories;
        //Returns only opjects with a quantity greater than 0, so it won't show anything you are out of
        var fillList = from q in inventories
                       where q.Qty > 0
                       select q;
        ingListLV.ItemsSource = fillList.ToList();
     }
var selectedObject = ingListLV.SelectedItem as Inventory;