Click here to Skip to main content
15,917,568 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi I have a wpf project which there I have a code like this :

C#
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
Posted

1 solution

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.
 
Share this answer
 
Comments
BaharDev 4-Oct-10 5:47am    
thanks for your answer but i think that's not the point since when i change listview to the normal one(i mean without array)it's ok but in array mode it provides exception like this and im not sure why

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900