NullReferenceException in ListView
-
Hi all i'm trying to check all items in a list view through a CheckAll checkbox option. now the problem is that when i click on the check all checkbox it gives me the NullReferenceException in the following code
private void AttributeList_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e)
{
attribute_list=attribute_list+"["+AttributeList.SelectedItem.ToString()+"],";
selected_columns.Add(AttributeList.SelectedItem.ToString());
}//end functionthe exception arises in the first line of the method all i'm trying to do is save the checked items in the list view. awaiting all replies Saira
-
Hi all i'm trying to check all items in a list view through a CheckAll checkbox option. now the problem is that when i click on the check all checkbox it gives me the NullReferenceException in the following code
private void AttributeList_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e)
{
attribute_list=attribute_list+"["+AttributeList.SelectedItem.ToString()+"],";
selected_columns.Add(AttributeList.SelectedItem.ToString());
}//end functionthe exception arises in the first line of the method all i'm trying to do is save the checked items in the list view. awaiting all replies Saira
-
Hello, Are you talking about System.Windows.Forms.ListView? Cause I can not find a SelectedItem Property there (only SelectedItems which is an Array). All the best, Martin
yes , i 'm talking about System.Windows.Forms.CheckedListBox and there is a property SelectedItem. does this help??
-
Hi all i'm trying to check all items in a list view through a CheckAll checkbox option. now the problem is that when i click on the check all checkbox it gives me the NullReferenceException in the following code
private void AttributeList_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e)
{
attribute_list=attribute_list+"["+AttributeList.SelectedItem.ToString()+"],";
selected_columns.Add(AttributeList.SelectedItem.ToString());
}//end functionthe exception arises in the first line of the method all i'm trying to do is save the checked items in the list view. awaiting all replies Saira
If I picture correctly what you doing, you looping through the listbox and setting the check. This does not imply that thge item being checked is selected. hence the value of the selecteditem is null. examine the selecteditems.count before using the code to see if it is not 0. or set the AttributeList.selecteditem = AttributeList.Items[loopcounter]; AttributeList.selecteditem.Checked = true; but I am not sure if that will fire the event.