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

[Solved] Setting Focused Record in Code

4 Answers 216 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Randall Nelson
Top achievements
Rank 1
Randall Nelson asked on 19 Mar 2009, 09:05 PM
I would like to offer the user of my application some navigation buttons such as Next Record and Last Record for working with the grid (in addition to the scrolling capabilities).  I am able to set the focused record, but have a couple of issues.  Here is my code for navigating to the last record:
        private void btnLast_Click(object sender, RoutedEventArgs e)  
        {  
            if (TheGrid.Records.Count == 0)  
                return;  
            Telerik.Windows.Data.Record dr = TheGrid.Records[TheGrid.Records.Count-1];  
            TheGrid.SelectedRecord = dr;  
        }  
 
This code does set the focused record to the last record.  However, if the last record is not currently in the view, the grid does not scroll so that you can see that record.  How can I set the focused record and scroll the grid to it?

Second, the carrot that points to the current record does not update - it still points to the old record.  But if you just pass the mouse over the carrot - it goes away.  If you pass the mouse over where the carrot should be on the record that you moved to it appears.  So it looks like a refresh issue.

Finally, I would like to know if there is an easier way to navigate to the next record.  Here is what I am doing:
        private void btnNext_Click(object sender, RoutedEventArgs e)  
        {  
            if (TheGrid.Records.Count == 0)  
                return;  
            Telerik.Windows.Data.Record CurrentRecord = TheGrid.CurrentRecord;  
            int CurrentIndex = TheGrid.Records.IndexOf(CurrentRecord);  
            CurrentIndex++;  
            if (CurrentIndex >= TheGrid.Records.Count)  
                return;  
            Telerik.Windows.Data.Record NextRecord = TheGrid.Records[CurrentIndex];  
            TheGrid.SelectedRecord = NextRecord;  
        }  
 

Thanks!

4 Answers, 1 is accepted

Sort by
0
Accepted
Stefan Dobrev
Telerik team
answered on 20 Mar 2009, 04:24 PM
Hello Randall,

Regarding your first question here is the code to bring a record into the viewport:

GridView.ItemsControl.BringRecordIntoView(GridView.SelectedRecord)

The current record focus carrot problem is a bug on our side that we are aware of. It will be fixed shortly.

About your last question this is the only way to move the current record back and forward. We may consider adding some handy extension methods that will do the work for you in the future version of the product.

Have a nice day,
Stefan Dobrev
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
Randall Nelson
Top achievements
Rank 1
answered on 20 Mar 2009, 08:25 PM
Thanks.  That code did the trick.
0
Jaime Bula
Top achievements
Rank 2
answered on 06 Apr 2009, 10:11 PM
Hi,

I tried this, but my code is a bit different:

if

(selObjItem != null)

 

{

GridLibraryResults.SelectedItem = selObjItem;

GridLibraryResults.ItemsControl.BringRecordIntoView(GridLibraryResults.SelectedRecord);

}

I get an ArgumentOutOfRangeException. I remove the last line, but the record is focused out of the view port.

Any Guess??

Jaime Luis Bula P.

 

0
Vlad
Telerik team
answered on 09 Apr 2009, 11:48 AM
Hello Jaime,

Can you send us an example ( via support ticket) which demonstrates your scenario and this exception? We will gladly help you to resolve this.

Regards,
Vlad
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
Randall Nelson
Top achievements
Rank 1
Answers by
Stefan Dobrev
Telerik team
Randall Nelson
Top achievements
Rank 1
Jaime Bula
Top achievements
Rank 2
Vlad
Telerik team
Share this question
or