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.

Scrolling in WPF Toolkit’s Column Chart - wanlan meng replied to Michael Detras on 25-Sep-13 05:10 AM

Hi,Michael Detras
I read the article you wrote 

http://www.nullskull.com/a/1487/scrolling-in-wpf-toolkits-column-chart.aspx
Now I want to add more data to the Chart,but the operating results are not ideal.Before the addition of XAML:
<Window x:Class="WPFToolkitChartScrollDemo.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="clr-namespace:WPFToolkitChartScrollControls;assembly=WPFToolkitChartScrollControls"
    xmlns:charting="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
    Title="MainWindow" Height="400" Width="500">
    <Grid>
        <charting:Chart>
            <charting:Chart.Series>
                <controls:ScrollableColumnSeries
                    IndependentValueBinding="{Binding Name}"
                    DependentValueBinding="{Binding Quantity}"
                    ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Window}, Path=Parts}"/>
            </charting:Chart.Series>
        </charting:Chart>
    </Grid>
</Window>

And After the additon of XAML:
<Window x:Class="WPFToolkitChartScrollDemo.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="clr-namespace:WPFToolkitChartScrollControls;assembly=WPFToolkitChartScrollControls"
    xmlns:charting="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
    Title="MainWindow" Height="400" Width="500">
    <Grid>
        <charting:Chart>
            <charting:Chart.Series>
                <controls:ScrollableColumnSeries
                    IndependentValueBinding="{Binding Name}"
                    DependentValueBinding="{Binding Quantity}"
                    ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Window}, Path=Parts}"/>
                <controls:ScrollableColumnSeries
                    IndependentValueBinding="{Binding Name}"
                    DependentValueBinding="{Binding Quantity}"
                    ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Window}, Path=Parts2}"/>

            </charting:Chart.Series>
        </charting:Chart>
    </Grid>
</Window>                                                                                                                                                                                                                      

When the scroll, only the series[0] data series change, while series[1] did not change. Can you help me? Thanks in advance!