Hi. my application let a user click somewhere and my xamDataGrid should change the selected row/active row accordingly.
I'm using ScrollCellIntoView to make the row visible to the user and it works.
however, this row appear sometimes in the top section and sometimes in the bottom section. I assume that it is related to how it is implemented, something like moving one row up or down until getting to that row.
This is unexpected behavior for my user, I would like to find a way to make it appear in the middle, can you suggest a way?
The code I'm using today is:
grid.SelectionSettings.SelectedRows.Clear(); grid.SelectionSettings.SelectedRows.Add(LogViewer.grid.Rows[rowIndex]); grid.ScrollCellIntoView(LogViewer.grid.Rows[rowIndex].Cells[0]);
I have also tried to 'trick' the funtion by calling ScrollCellIntoView to 10 lines before, than 10 lines after and than the actual line,
thinking this will cause it to appear in the middle, but it didn't do anything.
please help...
thanks.
Hello eligazit,
I apologize, I should've noticed from the code example that you had provided that you were using the XamGrid and not the XamDataGrid.
You are correct in that the XamGrid does not have a BringRecordIntoView method, and so I would recommend using the ScrollCellIntoView method instead, where the syntax for scrolling a particular cell in this case would be:
//Where "index" is a calculated index...theGrid.ScrollCellIntoView(theGrid.Rows[index].Cells[0]);
Regarding a replacement for the GetRecordsInView method, you can use the XamGrid's RowsPanel for this. You can get the RowsPanel by walking the visual tree of the XamGrid by using the Infragistics.Windows.Utilities class and its GetDescendantFromName method. Once you have the rows panel, that element has a VisibleRows property that returns the current rows in view. The implementation of this could look like the following:
RowsPanel rowPanel = Utilities.GetDescendantFromName(theGrid, "RowsPanel") as RowsPanel;var rowsInView = rowPanel.VisibleRows;
From there, the process is very similar to the XamDataGrid process, except you need to use the XamGrid.Rows collection, instead of the XamDataGrid.Records collection, and you need to index the cells of your row for the ScrollCellIntoView method.
I have attached a modified version of the original sample project I had sent you that uses the XamGrid instead of the XamDataGrid. I hope this helps you.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer
Hi,
sorry, I've publish the question in the xamDataGrid, instead of in the xamGrid.
It seems that the xamGrid does not contain the methods you mentioned, getRescordsInView and BringRecordIntoView, any other suggestion? the trick I'm using is not reliable, it does not always give the right result
I would recommend continuing with the "trick" that you are trying at the moment, where you are essentially telling the grid to scroll a cell into view that is 10 lines before or after the actual line that you wish to scroll, but I would recommend checking the count of the collection returned by the XamDataGrid.GetRecordsInView method first. This will allow you to perform a better calculation on where exactly to scroll into view. You may also want to consider using the BringRecordIntoView method as this is more on a "row" scope, but the ScrollCellIntoView method should work, too.
It is also worth noting that this functionality is currently expected behavior of the grid. When you scroll a cell or record into view that is currently out of view, the grid will determine whether or not the cell or record is above or below the currently shown records. If it is above it (scroll up), the record you are scrolling will appear at the top of the grid, and if below (scroll down), it will show at the bottom. If the cell or record is already in view, these scroll methods will not do anything.
By using the GetRecordsInView method of the XamDataGrid, you can find the records in view, find the index of those records relative to the one you wish to be scrolled to the middle, and bring an appropriate index into view in order to scroll your record or cell into the "middle" of the grid. I have attached a sample project to demonstrate the above.
I hope this helps you. Please let me know if you have any other questions or concerns on this matter.