public static GridViewRow FindGridRow(string textToFind, RadGridView rgv)
{
int verticalOffset = 0; // Holds the current vertical offset in the viewport
int viewPortHeight; // The height of the visible part of the grid
int extentHeight; // The total height of the grid, visible plus non-visible
// Grab the VirtualizingPanel contained in the RadGridView. This is used to control the viewable portion of the grid.
FrameworkElement VirtualizingPanel = rgv.Find.ByType("GridViewVirtualizingPanel");
// Detect the view port height and the extent height
viewPortHeight = (int)VirtualizingPanel.GetProperty(new AutomationProperty("ViewportHeight", typeof(int)));
extentHeight = (int)VirtualizingPanel.GetProperty(new AutomationProperty("ExtentHeight", typeof(int)));
// Make sure it is scrolled to the very top
// Walk through the entire grid verifying the data
VirtualizingPanel.InvokeMethod("SetVerticalOffset", 0);
while (verticalOffset < extentHeight)
{
foreach (GridViewRow row in rgv.Rows)
{
if (row.Find.AllByTextContent(textToFind).Count > 0)
{
return row;
}
}
// Scroll down one page
verticalOffset += viewPortHeight;
VirtualizingPanel.InvokeMethod("SetVerticalOffset", verticalOffset);
rgv.Refresh();
}
return null;
} |