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

Record Navigation

3 Answers 205 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sid
Top achievements
Rank 1
Sid asked on 12 Feb 2009, 11:01 PM
I'm in the middle of producing a new WPF app to replace an old Clipper application for one of my clients.  So I'm trying to develop a window framework for basic business objects.  I'm trying to build a generic user control which can facilitate the typical <First> <Prev> <Next> <Last> record navigation within a TabControl.  The first tabs are my RadGridViews which allow for sorting and searching capability.  The second tab is a details tab, which is where I would like to have this record navigation so the end user doesn't have to go back and forth between the tabs if they're just trying to move through the list.

I have the navigation working just fine but I would like to add a couple textboxes to the user control which would display the current record # and the total # of records.  I don't want to tightly couple the user control to the specific grid or page.  My user control is "bound" to the grid during the constructor method of the window.  I can easily get the current record during the click event of each of the 4 buttons but would prefer if the user control would update on any movement on the grid.  Also, I would like to have a user control property bound to the population of the grid data so the user control would know whenever a new search if performed within the grid and appropriately reset the two text boxes.  I'm just not quite sure how to do this and what event or property of the RadGridView I'd tie it to.  I'm new to WPF and C# so my guess would be some type of CommandBinding or DependencyProperty?

Any help would be greatly appreciated.

Thanks,
-Sid Meyers.

3 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 17 Feb 2009, 02:02 PM
Hello Sid,

I've created a sample application that demontrates how you can implement the functionality that you require with a minimal knowledge of RadGridView.  The trick is to wrap your data in a CollectionView and them bind your UserControl to the proprties of the CollectionView, instead to the RadGridView.

The only problem is the record count. Current we do not expose an easy way to determine that records have changed. You can try updating the record count every time the user clicks on the details tab.

Hope this works.

Greetings,
Milan
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
Sid
Top achievements
Rank 1
answered on 18 Feb 2009, 01:37 AM
Milan,

Here's my solution.  I did bind directly to the RadGridView.  In some of my business applications, my current Foxpro grids can contain 10,000+ records, haven't tried to stress test the RadGrids yet under WPF, but I didn't think I wanted to start down the road to create the CollectionView.

On the gridview tab I have the following code when my search parameters change: (I have a business object which controls the SQL interaction)

private void ChurchList_AlphaSearch(object sender, RoutedEventArgs e)
{
            this.grdChurches.ItemsSource = this.Church.GetChurchesByAlpha(ChurchAlphaSearchToolbar.TxtSearch.Text);
            this.navChurchBar.scsGridView = this.grdChurches;
}

So this binds my gridview control to the navigation control.  Then in the "set" section for my gridview property of the navigation control:

            set
            {
                _scsGridView = value;
                this.txtCurrentRecord.Text = "1";
                this.txtTotalRecords.Text = " Of " + _scsGridView.Records.Count.ToString();
            }

So I now have the total records.

Then on my navigation buttons:

       private void buttonNext_Click(object sender, RoutedEventArgs e)
        {
            RadGridView gridView = this.scsGridView;
            int currentrecord = gridView.ItemsControl.Records.IndexOf(gridView.CurrentRecord);
            if (currentrecord < gridView.Records.Count - 1)
            {
                currentrecord = currentrecord + 1;
            }

            Record record = gridView.ItemsControl.Records[currentrecord];
            gridView.CurrentRecord = record;
            this.txtCurrentRecord.Text = (currentrecord + 1).ToString();
        }


I've also added the ability for the user to input a number in the current record text box:

        private void MoveToRecord(object sender, RoutedEventArgs e)
        {
            RadGridView gridView = this.scsGridView;
            Record record = gridView.ItemsControl.Records[(int.Parse(this.txtCurrentRecord.Text)-1)];
            gridView.CurrentRecord = record;
        }


I haven't setup the enable and disable of the buttons as yet but it seems to be working so far!  So now I have the navigation user control which I can drop in my details tabs and wire up with a couple lines of code.

Thanks for the reply.  Let me know if you see anything that might cause an issue in my post.

-Sid Meyers.
0
Milan
Telerik team
answered on 19 Feb 2009, 03:49 PM
Hello Sid,

Everything seems ok.
It you have any questions do not hesitate to ask.

All the best,
Milan
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
Sid
Top achievements
Rank 1
Answers by
Milan
Telerik team
Sid
Top achievements
Rank 1
Share this question
or