Click here to Skip to main content
15,892,674 members

NullReference thrown when the object is not null

Member 8036175 asked:

Open original thread
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....
Tags: C#, WPF, DataGrid, Event

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900