LoadingRowDetails event : Selected Item is item of previous selected row


  • Hi everyone,

    In SL4 I have a DataGrid and a RowDetailsTemplate. In the RowDetailsTemplate I need to rework and show some information based on the crrently selected item.

    The problem is that it returns the selected item of the previously selected row. Any ideas how to get around this, here is some sample code ? :

    private void grdMain_LoadingRowDetails(object sender, System.Windows.Controls.DataGridRowDetailsEventArgs e)
                TextBlock txtbox = e.DetailsElement.FindName("txtDetails") as TextBlock;
                DataGrid snd = sender as DataGrid;
                Worker currentRow = (Worker)snd.SelectedItem;  // <<<< PROBLEM !!! : THIS IS THE PREVIOUS ROW'S DETAILS
                txtbox.Text = "details will come here ...";

    Wednesday, June 29, 2011 2:08 AM


  • Awesome !!! Thanks so much Asim for putting me on the right path with this.

    I figured out that the problem is not due to the LoadingRowDetails event but it has to do with the way I have obtained the SELECTED item. For those who encounter a similar problem :

    This DOES NOT work : Worker currentRow = (Worker)grdMain.SelectedItem;

    But this WORKS : Worker currentRow = (Worker)e.Row.DataContext;

    Wednesday, June 29, 2011 4:19 AM

All replies