DataGrid RowDetails Refresh Problem

Oct 12, 2009 at 8:48 PM
I'm getting desperate for a solution to this problem. I'm made a number
of different posts documenting my attempts to solve this from different
angles and I've received no response.

Again, the issue is that when a top level DataGrid's ItemsSource is
re-queried, any row selection made on a DataGrid (contained within
RowDetailsTemplate of the top level DataGrid) is lost, the selection's
RowDetails are collapsed, and these previous user selections can't seem
to be recovered in any programmatic way.

Thanks,

Bill
Oct 13, 2009 at 8:17 PM
Finally figured this one out, or at least a good part of it. I found this:
http://www.codeplex.com/wpf/Thread/View.aspx?ThreadId=37823 which got me
close enough.

The DataGridRowEventArgs event args of the LoadingRow event has Row
property. It in turn exposes an Items collection where each item is a field
from the EntitySet. The Row property also exposes an IsSelected property and
setting this to true for the desired row does work.

However, if for some rows the RowDetails contain other controls like combo
boxes, and the DataContext for these other controls is not the same as the
grid, and the LoadingRowDetails event takes care of setting the DataContext
and SelectedIndex of the ComboBox, this leads to some very unsightly
updating. Wrapping the setting of the DataContext inside a
ComboBox.Items.DeferRefresh() does not help. But I suppose all that is for
another thread.

Here's a sample LoadingRow event handler:
private void DspGrid_LoadingRow(object sender, DataGridRowEventArgs e) {
if (selectedDspPrimaryKeys.Count == 0) return;

// find the DataTable row that this DataGrid row is assocaited with
Dsp dsp = e.Row.Item as Dsp;

// find its PK
string pk = dsp.DspSerial.ToString();

// determien whether it should be selected
if (selectedDspPrimaryKeys.Contains(pk)) {
e.Row.IsSelected = true;
selectedDspPrimaryKeys.Clear();
}
}

Somewhere before you reset the ItemsSource for the grid, load the pk of the
record into a List<string>.


I hope somebody else finds this useful.


Bill

On 10/12/2009 3:48 PM, wpmccormick wrote:
>
>
> From: wpmccormick
>
> I'm getting desperate for a solution to this problem. I'm made a number
> of different posts documenting my attempts to solve this from different
> angles and I've received no response.
>
> Again, the issue is that when a top level DataGrid's ItemsSource is
> re-queried, any row selection made on a DataGrid (contained within
> RowDetailsTemplate of the top level DataGrid) is lost, the selection's
> RowDetails are collapsed, and these previous user selections can't seem
> to be recovered in any programmatic way.
>
> Thanks,
>
> Bill
>
> Read the full discussion online
> <http://wpf.codeplex.com/Thread/View.aspx?ThreadId=71745&ANCHOR#Post244819>.
>
> To add a post to this discussion, reply to this email
> ([email removed]
> <mailto:[email removed]?subject=[wpf:71745]>)
>
> To start a new discussion for this project, email
> [email removed] <mailto:[email removed]>
>
> You are receiving this email because you subscribed to this discussion
> on CodePlex. You can unsubscribe or change your settings
> <https://wpf.codeplex.com/subscriptions/thread/project/edit> on
> codePlex.com.
>
> Please note: Images and attachments will be removed from emails. Any
> posts to this discussion will also be available online at codeplex.com
>