Silverlight / WPF - wpf datagrid custom paging and datagrid selection changed event

Asked By Mallikarjuna on 07-Oct-10 01:48 AM
hi everyone ,i am new to wpf .I have implemented wpf Datagrid custom paging as given in this forum.It works perfectly but if  i select a row in the datagrid to raise the datagrid_selectioncanged event handler ,first time selection changed event handler is executed but after if i click  >  command(at this time already one datagrid row is selected) in paging it will give the error like
 "object reference is not set to object instance" in the following line of code

  int id=int.parse(datagrid.selectedvalue.ToString());

 But I get confused that ,if i click Next (>)command it wont go to Next Command instead it will come to selectionChanged event .Please tell me how to solve this problem.
Michael Detras replied to Mallikarjuna on 07-Oct-10 02:33 AM
Hi, the reason why the SelectedValue becomes null is because the ItemsSource of the DataGrid is changed when you click on the Next button. The currently selected item won't be found in the new ItemsSource. Either you check if the SelectedValue is null or set a default selection (like the first item) before you call int.parse().
Mallikarjuna replied to Michael Detras on 07-Oct-10 10:23 AM
  wow, Thanks Michael Detras.Its Perfectly working.this is my first question to the forum.