对象引用未设置为我的列表视图的对象实例 [英] Object reference not set to an instance of an object for my listview

查看:77
本文介绍了对象引用未设置为我的列表视图的对象实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个wpf项目,那里有这样的代码:

 ListView [] myList =  ListView [ds.Tables [ 0 ] .rows.Count];
         for ( int  i =  1 ; i <  ds.Tables [ 0 ].Rows.Count; i ++)
        {
            myList [i] .ItemsSource = ds.Tables [ 0 ].DefaultView;
           
        } 



但在本部分中,myList [i] .ItemsSource = ds.Tables [0] .DefaultView;

我得到的对象引用未设置为对象异常的实例,并且我不知道我在哪里错了,有人可以告诉我我的错误在哪里吗? ="h2_lin">解决方案

错误
我得到未设置为对象异常实例的对象引用

未初始化要分配的对象时可能会发生错误,
在对特定对象进行任何操作之前,请确保其不为空,

在这里

ds.Tables[0].DefaultView;


可能尚未初始化,

确保已正确初始化DataSet的对象,


如果有帮助,请 投票 接受答案 .


Hi I have a wpf project which there I have a code like this :

ListView[] myList = new ListView[ds.Tables[0].Rows.Count];
        for (int i = 1; i < ds.Tables[0].Rows.Count; i++)
        {
            myList[i].ItemsSource =  ds.Tables[0].DefaultView;
           
        }



but in this part myList[i].ItemsSource = ds.Tables[0].DefaultView;

i get the Object reference not set to an instance of an object exception and i dont have any idea where I am wrong,could someone tell me where is my mistake ??thanksss

解决方案

Error
I get the Object reference not set to an instance of an object exception

Error probably occurs when object you are assigning is not initialized,
before making any of the operation with particular object make sure that it is not null,

Here

ds.Tables[0].DefaultView;


May not have been initialized,

Make sure that object of DataSet is initialized properly,


Please vote and Accept Answer if it Helped.


这篇关于对象引用未设置为我的列表视图的对象实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆