i got small error in c#

Posted by Kannan1986 under C# on 3/9/2010 | Views : 1317 | Status : [Member] | Replies : 2
Hi all,

i got small error in c# ...




lstSelected.Items.Add(lstAvail.SelectedItem);

lstAvail.Items.Remove(lstAvail.SelectedItem);


when i execute a code i make a error ...


Error:

object reference not set to an instance of an object...




Responses

Posted by: Kunal2383 on: 3/9/2010 [Member] Starter

Up
0
Down

Hi Kannan,

The error message "object reference not set to an instance of an object" comes when you are accessing any object which has not been initialized yet, simply saying, the object is null.

So, before doing the remove operation if you can check the lstAvail.Items count I think this will be resolve. And also before removing check whether the SelectedItem is present in the list. If present then remove it.

Please "Mark As Answer" if this answered your query.

Thanks & Regards,
Kunal Chowdhury | http://www.kunal-chowdhury.com | http://twitter.com/kunal2383

Kannan1986, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sagarp on: 3/24/2010 [Member] Bronze

Up
0
Down
check following

http://www.java2s.com/Tutorial/VB/0260__GUI/CheckedListBoxAddItemsGetSelectedItemsandGetSelectedIndices.htm

Thanks
SagarP
http://www.emanonsolutions.net
http://emanonsolutions.blogspot.com/

Kannan1986, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response