Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am new to wpf, i m using a editable comboBox (for search purpose). When text in ComboBox is changed, below datagrid displays the search result. when any row from the datagrid is selected its values are displayed in textboxes for editing.
when i write something in combobox the realated row are displayed in the data grid.. but when i, click to select a row, application throws a nullreference exception.
My application worked correctly when the dataGrid refreshing logic was behind a button click.

the code for "SelectionChange" Event of the dataGrid is:

C#
private void CategoryRowSelected(object sender, System.Windows.Controls.SelectedCellsChangedEventArgs e)
		{
			ClearForm();

          if(CategoryDataGrid.SelectedItem!=null)
           {
           
             categoryMember = CategoryDataGrid.SelectedItem as CategoryTbl; // value assigned to the object
            // if (categoryMember != null)
             CategoryName.Text = categoryMember.CategoryName; //Exception thrown on this statement
             CategoryDescription.Text = categoryMember.CategoryDescription;
    
           } 		
        }
and code for the textChange event of ComboBox is:

private void RefreshDataGrid(object sender, System.Windows.Controls.TextChangedEventArgs e)
        {
            CategoryDataGrid.SelectedIndex = -1;           
            //CategoryDataGrid.ItemsSource = RefreshQuery;
            CategoryDataGrid.ItemsSource= Admin.RefreshCategoryDataGrid(NameCombo.Text);
        }


I hope to get an answer sooon....
Posted
Updated 25-Sep-12 9:11am
v2

1 solution

The possibilities are pretty obvious:
1) categoryMember is null, either because CategoryDataGrid.SelectedItem is null, or is not a CategoryTbl,
or
2) CategoryName is null.

Put a breakpoint on the first line of the handler, and step through until you find out which. Then you can either fix it, or let us know (and show the relevant code) and we can have a look.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 25-Sep-12 17:53pm    
Right, my 5. OP's logic was incorrect.
--SA

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