using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Telerik.Windows.Data;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.GridView;

namespace RGV_WPF_VisibleRows_NoXAML
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private int GetLastVisibleIndexFromAllRealized()
{
    var rows = this.clubsGrid.ChildrenOfType<GridViewRow>();
 
        int lastIndex = 0;
        foreach (var row in rows)
        {
            int index = this.clubsGrid.Items.IndexOf(row.Item);
            if (lastIndex < index)
            {
                lastIndex = index;
            }
        }
    
        return lastIndex;
}

private int GetFirstVisibleIndexFromAllRealized()
{
    var rows = this.clubsGrid.ChildrenOfType<GridViewRow>();
    int firstIndex = -1;
    foreach (var row in rows)
    {
        int index = this.clubsGrid.Items.IndexOf(row.Item);
        if (firstIndex == -1 || firstIndex > index)
        {
            firstIndex = index;
        }
    }

    return firstIndex;
}

        private void Button1_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show(string.Format("The first index detected is {0}" , GetFirstVisibleIndexFromAllRealized().ToString()));
        }

        private void Button2_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show(string.Format("The last index detected is {0}", GetLastVisibleIndexFromAllRealized().ToString()));
        }
    }
}
