i have 2 web datagrids that are in a master detail relationship. I currently highlight the most relevant record in the child grid but have been unable to scroll it programatically into view if it is not currenlly visible. I have used selected row to highlight the field and have also set active row to the same field. however, i still have to scroll manually to the highlighted record. How can i get the row that is selected and active to also be visible. tks. i am using VB codebehind to do all of this.
Hello Garry,
You can use ScrollTop property of the WebDataGrid component in order to adjust the scrollbar position according to your requirements. Suppose you have a grid with 30 records and on postback raised by button you would like to select a row form server-side and then scroll to view you can use code similar to to this one below:
Protected Sub Button1_Click(sender As Object, e As EventArgs)
WebDataGrid1.Behaviors.Selection.SelectedRows.Add(WebDataGrid1.Rows(19))
WebDataGrid1.ScrollTop = 380
End Sub
Hope this helps.
Let me know if you have any questions with this?
Thanks.
Hello Radoslav,
I can set the scroll top property and position the the bar. However, how do you calculate the correct value for scrolltop. I have tried different scenarios for calculating the value but cannot find a source that will allow me to calculate an effective value. As i said i am trying to position to the currently active or select row.
Best Regards
Hello,
Let say that we have a grid with 100 rows and we want to set the 60-th row as selected and we want to show it in grid view on postback.
You can do something like this in server code:
protected void Button1_Click(object sender, EventArgs e)
{
//Select a row
WebDataGrid1.Behaviors.Selection.SelectedRows.Add(
WebDataGrid1.Rows[60]);
//Get the index of the selected row.
int selectedRowIndex =
WebDataGrid1.Behaviors.Selection.SelectedRows[0].Index;
int result = 30 * selectedRowIndex;
//Scroll the grid
WebDataGrid1.ScrollTop = result;
}
Any additional info on how to calculate the toprow value? Espeically , how to get row height(s) in code behind to help in accurately positioning the scrollbar?
Hi Mancusor,
You can use something like this function to scroll to the active cell:
function scrollToActiveCell() { var grid = $find("WebDataGrid1"); grid.get_behaviors().get_activation().get_activeCell().scrollToView();}
Did you ever get an answer to your question?
I'm having the same problem. My grid heights vary depending on the amount of data returned.
Mancusor
Hi Radoslav,
Your Suggested Solution is working Fine, with Fixed height and if Scroll Is there in Grid,
If I have enabled Paging with say PageSize = 10, I dosen't work
Kindly let me what could be causing the issue or If I'm Missing something
Regards,
Abhishek
Because the height of the rows changes depending on the content, having a fixed value will not always work. I am experiencing a drift in the positioning as the rows with non standard heights are encountered, causing the selected row to not be in the viewable area by the time i am further down towards the end of the grid. If i could capture the exact height of each preceding row and sum it, any drift would be inconsequential. Is there any way to access the exact row height in vb code behind? If not they i would request that this be made availalbe in a future release and will accept that this approximation is as close as i can get?
One row is 20 px but you can consider it as 30 in order to calculate the "footer , header and so on.." because of that I'm calculating 30 * rowIndex