I have a grid with large number of records and child rows attached. If I scroll down to even one page and chagne the value of a child row's cell, as soon as i leave the cell scroll bar goes back to the top which is causing hard time because you have to scroll down again and find the record to update other cells.
I have tested with another project as soon as we execute 'e.Row.ViewTemplate.Refresh(); ' it took the scroll bar back to top I have tried other functions too but problem persist. It is a bug in Q2 2011?
Thanks
4 Answers, 1 is accepted
Thank you for your question.
Calling the Refresh method of ViewTemplate resets the values of the RadGridView's scrollbars. If your scenario requires this refresh, you can keep the value of the vertical RadGridView scrollbar as demonstrated in the following code snippet:
RadScrollBarElement scrollBar =
this
.radGridView1.TableElement.VScrollBar;
int
scrollBarValue = scrollBar.Value;
e.Row.ViewTemplate.Refresh();
if
(scrollBar.Minimum <= scrollBarValue && scrollBar.Maximum >= scrollBarValue)
{
scrollBar.Value = scrollBarValue;
}
I hope it helps.
Best regards,
Alexander
the Telerik team
Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>
private void MasterTemplate_CellValueChanged(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
{
if (e.Row.HierarchyLevel == 1)
{
if (e.Row.HasChildRows())
{
foreach (GridViewRowInfo item in e.Row.ChildRows)
{
item.ViewTemplate.Refresh();
}
}
}
else if (e.Row.HierarchyLevel != 0)
{
DataAccess.ProductPrice child = (DataAccess.ProductPrice)e.Row.DataBoundItem;
Type childType = child.GetType();
System.Reflection.PropertyInfo prop = childType.GetProperty(e.Column.FieldName);
try
{
if (prop != null)
{
if (!IsNumeric(e.Value))
{
if (prop.Name == "MetaTag")
{
prop.SetValue(child, ((string)e.Value).Substring(0, 60), null);
}
else
{
prop.SetValue(child, ((string)e.Value), null);
}
}
else
{
prop.SetValue(child, (decimal)e.Value, null);
}
}
RadScrollBarElement scrollBar = this.rgvProducts.TableElement.VScrollBar;
int scrollBarValue = scrollBar.Value;
e.Row.ViewTemplate.Refresh();
if (scrollBar.Minimum <= scrollBarValue && scrollBar.Maximum >= scrollBarValue)
{
this.rgvProducts.TableElement.VScrollBar.Value = scrollBarValue;
}
//e.Row.ViewTemplate.Refresh();
}
catch(InvalidCastException ex)
{
MessageBox.Show("Given Value is not acceptable by the column. Details: " + ex.Message, "Format Exception", MessageBoxButtons.OK);
prop.SetValue(child,null, null);
}
}
}
Thank you for the reply. I tested your code but behavior is very strange. If I use your code or not, after changing the value hit Enter first time vertical scroll bar will go on top, after that it will never go on top works normal. But if I use TAB after changing value with your code or without always go on Top. To make it easy I am pasting the code here.
Thanks
Hi Alxander,
I just tested if I use below line of Code after setting integer value of VScrollBar works fine with Enter Key but with TAB key or lose focus of the cell with mouse then no chance.
Thanks
this.rgvProducts.TableElement.VScrollBar.UpdateLayout();
Thank you for the provided code snippet and additional details.
RadGridView scrolls to its top records when the user changes a value in the child template's relation column. This change removes the child row from this template and the Refresh method of the child template leads to the undesired scrolling of the control.
This behavior of RadGridView will be addressed in the upcoming service pack, scheduled for the beginning of September.
Best regards,
Alexander
the Telerik team
Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>