We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Grid with ObservableCollection ItemsSource: Iterate over records

Hi,

I have a Syncfusion WPF grid with an ObservableColletion<T> as data source with columns A, B, and C.  The grid is grouped and sorted by column A, lets say 3 items in the A group and 5 items in the B group and 2 in the C group.   I want to create a command that will iterate through the records in such a way that the first record under A [0-based index=0] is selected first.  Invoking the command again should highlight the first item in group B
[index=3].  Invoking it a third time the selection and the selected highlight should move to the first item in the C group [index=8].

In the Xaml I have:
SelectedItem="{Binding Item, Mode=TwoWay}"

I would expect that assigning the SelectedItem in the ViewModel in through code would change the selected item and highlight.  This does not seem to work :(

I then tried to select record with index 3 manually by using
grid.Model.Selections.Add(GridRangeInfo.Row(3));
- while the highlight changes, I don't know how to get a mapping between the model data and the row index required by GridRangeInfo.Row().

Hope you can help,

Best regards,

Friedrich

1 Reply

RG Rajasekar G Syncfusion Team December 26, 2012 10:40 AM UTC

Hi Friedrich,

 

Thank you for your interest in Syncfusion products.

 

We have analyzed your query and you can achieve your requirement by using the following code snippet.

 

Code snippet[C#]:

grid.Model.SelectedRanges.Add(GridRangeInfo.Row(rowindex));

grid.Model.Grid.InvalidateCell(GridRangeInfo.Row(rowindex));

We have prepared a sample based on this and it can be download from the following location.

Sample Location: http://www.syncfusion.com/downloads/Support/DirectTrac/102493/GridDataControlSample1122105268.zip

Note:

1.       Run the sample.

2.       Click the button AddSelectedRange button to select the first record from group.

And you can map the recordindex and rowindex by using the following code snippet.

Code Snippet[C#]:

//record index from the rowindex
int recordindex = grid.Model.ResolveIndexToRecordPosition(rowindex);
 
//rowindex from the recordindex
int rowindex = grid.Model.ResolvePositionToIndex(recordindex);

Please let us know if you have any questions.

Regards,

Raja sekar.G


Loader.
Live Chat Icon For mobile
Up arrow icon