Click here to Skip to main content
13,146,014 members (41,934 online)
Rate this:
Please Sign up or sign in to 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:

private void CategoryRowSelected(object sender, System.Windows.Controls.SelectedCellsChangedEventArgs e)
             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 25-Sep-12 8:57am
Updated 25-Sep-12 9:11am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

The possibilities are pretty obvious:
1) categoryMember is null, either because CategoryDataGrid.SelectedItem is null, or is not a CategoryTbl,
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.
Sergey Alexandrovich Kryukov 25-Sep-12 17:53pm
Right, my 5. OP's logic was incorrect.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170915.1 | Last Updated 25 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100