Full sample code behind in data navigatior

Published 22 June 09 03:45 AM

    public partial class Window1 : Window

    {

        private WpfDataNavigationApplication.NorthwindEntities northwindEntities = new WpfDataNavigationApplication.NorthwindEntities();

        private System.Windows.Data.CollectionViewSource employeesViewSource__NorthwindEntities;

        System.Data.Objects.ObjectQuery<WpfDataNavigationApplication.Employee> employeesQuery;

        private int totalRowCount;

 

        public Window1()

        {

            InitializeComponent();

        }

 

        private System.Data.Objects.ObjectQuery<Employee> GetEmployeesQuery(NorthwindEntities northwindEntities)

        {

            // Auto generated code

            System.Data.Objects.ObjectQuery<WpfDataNavigationApplication.Employee> employeesQuery = northwindEntities.Employees;

           

            // Returns an ObjectQuery.

            return employeesQuery;

        }

 

        private void Window_Loaded(object sender, RoutedEventArgs e)

        {

           employeesViewSource__NorthwindEntities = ((System.Windows.Data.CollectionViewSource)(this.FindResource("employeesViewSource__NorthwindEntities")));

           employeesQuery = this.GetEmployeesQuery(northwindEntities);

           employeesViewSource__NorthwindEntities.Source = employeesQuery.Execute(System.Data.Objects.MergeOption.AppendOnly);

 

           totalRowCount = northwindEntities.Employees.Count();

           totalRowCountLabel.Content = totalRowCount;

          

           UpdateNavigatorUI();

        }

 

        private void GoToFirstButton_Click(object sender, RoutedEventArgs e)

        {

            employeesViewSource__NorthwindEntities.View.MoveCurrentToFirst();

            UpdateNavigatorUI();

        }

 

        private void GoToPreviousButton_Click(object sender, RoutedEventArgs e)

        {

            employeesViewSource__NorthwindEntities.View.MoveCurrentToPrevious();

            UpdateNavigatorUI();

        }

 

        private void GoToNextButton_Click(object sender, RoutedEventArgs e)

        {

            employeesViewSource__NorthwindEntities.View.MoveCurrentToNext();

            UpdateNavigatorUI();

        }

 

        private void GoToLastButton_Click(object sender, RoutedEventArgs e)

        {

            employeesViewSource__NorthwindEntities.View.MoveCurrentToLast();

            UpdateNavigatorUI();

        }

 

        private void GoButton_Click(object sender, RoutedEventArgs e)

        {

            int position;

            int.TryParse(goTextBox.Text, out position);

            if (position > 0 && position <= totalRowCount)          

{

employeesViewSource__NorthwindEntities.View.MoveCurrentToPosition(position - 1);

}

            else

            {

                MessageBox.Show("The input index is not valid.");

            }

        }

 

        private void SetGoTextBoxOnCurrentPosition()

        {

            goTextBox.Text = (employeesViewSource__NorthwindEntities.View.CurrentPosition + 1).ToString();

        }

 

        private void SetButtonIsEnabled()

        {

            bool isFirst = (employeesViewSource__NorthwindEntities.View.CurrentPosition == 0);          

bool isLast  = employeesViewSource__NorthwindEntities.View.CurrentPosition > (totalRowCounts - 1);

 

            goToFirstButton.IsEnabled = goToPreviousButton.IsEnabled = !isFirst;

            goToNextButton.IsEnabled = goToLastButton.IsEnabled = !isLast;

 

        }

 

        private void UpdateNavigatorUI()

        {

SetGoTextBoxOnCurrentPosition();

SetButtonIsEnabled();

  }

}

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required

This Blog

Syndication

Page view tracker