Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WPF Events DataGrid
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)
		{
			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 25-Sep-12 9:57am
Edited 25-Sep-12 10:11am
v2

1 solution

Rate this: bad
good
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,
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.
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 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)

  Print Answers RSS
0 BillWoodruff 360
1 Mathew Soji 309
2 DamithSL 225
3 Afzaal Ahmad Zeeshan 202
4 Maciej Los 190
0 OriginalGriff 6,249
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 3,865


Advertise | Privacy | Mobile
Web03 | 2.8.1411019.1 | Last Updated 25 Sep 2012
Copyright © CodeProject, 1999-2014
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