This is a migrated thread and some comments may be shown as answers.

Determine is Row or Cell in sight

7 Answers 202 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Anton Khramov
Top achievements
Rank 1
Anton Khramov asked on 16 Sep 2008, 01:23 PM
Hi all.

I want to determine if Row or Cell in sight.
I checked IsVisible field of RowGridView but it always true. IsVisible
property of GridViewCell is true at first. After i had moved it out of visible area
it became false. After that it was alway false even if row was in visible are of
grid.

Regards, Anton.

7 Answers, 1 is accepted

Sort by
0
Atanas
Telerik team
answered on 18 Sep 2008, 12:33 PM
Hello Anton Khramov,

Currently we do not have a common API to determine whether a GridViewRow is visible or not.

Could you, please elaborate on how to reproduce your scenario? I would suggest you take a look at BringDataItemIntoView method of the RadGridView control:

this.radGridView.BringDataItemIntoView(dataRows[0]); 

Using this method you can  be sure that your GridViewRow is in sight.

Hope this helps.

Regards,
Atanas
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Anton Khramov
Top achievements
Rank 1
answered on 19 Sep 2008, 08:55 AM
Hi, Atanas.

Thank you for replay.
I,m using this method to bring  a row in view. And I don't want to exesute it when row already in view.

For exemple, i need to bring GridViewCell cell; into view using followed code:
private void radGridView_SelectionChanged(object sender, SelectionChangeEventArgs e)  
{      
     if (PageIsValid)  
     {  
          CurrentItem = radGridView.CurrentItem;  
     }  
}   
 
private void radGridView_MouseDown(object sender, MouseButtonEventArgs e)  
{  
       if (!cell.IsVisible && !PageIsValid)  
       {  
             radGridView.BringDataItemIntoView(CurrentItem);  
       }  

So, I have the trouble described above.

Regards,
Anton.
0
Pavel Pavlov
Telerik team
answered on 22 Sep 2008, 02:17 PM
Hello Anton Khramov,

Since our RadGridView has no API to determine whether an Item is in the ViewPort or not, I have prepared a small external method which could check this for you . You may put this method in your class. It will search over the visible items and check if the given one is in sight. You need to pass the RadGridView and the Item  as parameters.


private static  bool IsItemInViewPort(RadGridView gridView, object item)  
        {  
            GridViewItemsControl gridViewItemsControl = (GridViewItemsControl)gridView.Template.FindName("PART_RootItemsControl", gridView);  
            ScrollViewer scrollviewer = (ScrollViewer)gridViewItemsControl.Template.FindName("PART_ItemsScrollViewer", gridViewItemsControl);  
            ScrollContentPresenter scrollcontentpresenter = (ScrollContentPresenter)scrollviewer.Template.FindName("PART_ScrollContentPresenter", scrollviewer);  
            GridViewVirtualizingPanel panel = (GridViewVirtualizingPanel)VisualTreeHelper.GetChild((DependencyObject)scrollcontentpresenter.Content, 0);  
 
            double itemVerticalOffset = 0;  
            int rowIndex = 0;  
 
            while (itemVerticalOffset < panel.ActualHeight && rowIndex < panel.Children.Count)  
            {  
                GridViewRow rowToCheck = (GridViewRow) VisualTreeHelper.GetChild(panel, rowIndex);  
 
                if (((DataRecord)rowToCheck.Record).Data == item)  
                    return true;  
                rowIndex++;  
                itemVerticalOffset += rowToCheck.ActualHeight;  
            }  
 
            return false;  
        } 


Kind regards,
Pavel Pavlov
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Greg
Top achievements
Rank 1
answered on 23 Feb 2009, 02:46 PM
Hi All,

Tried to use fragment of code:

GridViewItemsControl gridViewItemsControl = (GridViewItemsControl)this.radGridView1.Template.FindName("PART_RootItemsControl", this.radGridView1);
ScrollViewer sv  = (ScrollViewer)gridViewItemsControl.Template.FindName("PART_ItemsScrollViewer", gridViewItemsControl); 


But it throws:

Unable to cast object of type 'Telerik.Windows.Controls.GridView.GridViewScrollViewer' to type 'System.Windows.Controls.ScrollViewer'.

Maybe I'm doing something wrong! I'm using RadControls_for_WPF_2008_3_1217_TRIAL.msi

Grego
0
Valeri Hristov
Telerik team
answered on 24 Feb 2009, 10:10 AM
Hi g,

The latest official version of RadGridView replaced the ScrollViewer controls with custom GridViewScrollViewer controls, hence the error. The code examples below seem to be obsolete. I would suggest changing the ScrollViewer in the following line to GridViewScrollViewer:
ScrollViewer sv = (ScrollViewer)gridViewItemsControl.Template.FindName("PART_ItemsScrollViewer", gridViewItemsControl);

GridViewScrollViewer sv = (GridViewScrollViewer)gridViewItemsControl.Template.FindName("PART_ItemsScrollViewer", gridViewItemsControl);

All the best,
Valeri Hristov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Greg
Top achievements
Rank 1
answered on 24 Feb 2009, 11:41 AM
Hi Valeri,

I would like to achieve the following functionality: Press button and scroll automatically one page or line.

I already try GridViewScrollViewer,but using this object I cannot find way to:
- get VerticalOffset
- invoke PageDown
- invoke LineDown

These members are available in standard ScrollViewer.
So GridViewScrollViewer doesn't give me what I need. Could you suggest me other solution?

Thanks in advance!

Grego
0
Valeri Hristov
Telerik team
answered on 25 Feb 2009, 03:25 PM
Hello Grego,

I found a simple application that demonstrates how to implement custom scrolling. Please, find it attached and let me know if it does not work for you.

Best wishes,
Valeri Hristov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Anton Khramov
Top achievements
Rank 1
Answers by
Atanas
Telerik team
Anton Khramov
Top achievements
Rank 1
Pavel Pavlov
Telerik team
Greg
Top achievements
Rank 1
Valeri Hristov
Telerik team
Share this question
or