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

Issues Scrolling to selected record

3 Answers 145 Views
GridView
This is a migrated thread and some comments may be shown as answers.
KawaUser
Top achievements
Rank 2
KawaUser asked on 20 Jun 2013, 03:54 PM
I am executing the code below following a refresh from the database.  What I'm trying to make happen is that after a process completes to update one of the rows, the data is refreshed and the previously selected record is still selected for the user and scrolled into view.  When I execute this code following an update routine the grid is scrolled completely to the bottom, and both the record I selected and the visible row within the grid (even though it is now a different row) is selected.  If I execute it from a command button, the first record is selected and the grid is scrolled completely to the top.  What am I doing wrong?

datagridview1.DataSource = Nothing
datagridview1.DataSource = Log_Table
If Log_Table.Rows.Count > 0 Then
    ' Log_Rec = Log_Table.First
    Dim Row As Telerik.WinControls.UI.GridViewRowInfo
    For Each Row In datagridview1.Rows
 
        If Row.Cells("Rec_ID").Value = RecID Then
            Row.IsSelected = True
        Else
            Row.IsSelected
= False
        End If
    Next
 
    For Each Row In datagridview1.Rows
        If Row.IsSelected Then
  Row.EnsureVisible()
        End If
    Next
End If

3 Answers, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 25 Jun 2013, 01:36 PM
Hi Derrik,

Thank you for writing.

There are better ways to update RadGridView after a row has been edited in the database. You can simply invalidate the row where the change happened or if your data item implements the INotifyPropertyChanged the grid will detect these changes for you and will update automatically. I would kindly ask you to send me a more detailed explanation of your setup so I can help you find a suitable solution for your scenario. I would need to know how you have set up the grid, how you get your data from the database, how you populate the grid and anything else you think might be useful. 

Looking forward to your reply.

Regards,
Ivan Petrov
Telerik
RadChart for WinForms is obsolete. Now what?
0
KawaUser
Top achievements
Rank 2
answered on 26 Jun 2013, 02:51 PM
To answer some of your questions, I use stored procedures to update, add, delete from my database.  I load the table as seen below.  I either load a datatable with a table adapter or load the grid directly from the table adapter using a getdata method.   I'm completely unfamilar with the INotifyPropertyChanged or the invalidate methods you mentioned so I would appreciate knowing more if you could point me in the right direction.

That being said, I still would like to scroll to a disgnated record afterward my refresh, so for that purpose am I doing something wrong below?
0
Ivan Petrov
Telerik team
answered on 01 Jul 2013, 01:38 PM
Hi Derrick,

Thank you for writing back.

You can read more on the INotifyPropertyChanged and INotifyCollectionChanged in the respective sections of MSDN. There are many many articles written on this matter so you should be able to find plenty of information online.

On your question I tested your code and made a slight adjustment. Here is the code that worked on my machine:
datagridview1.DataSource = Nothing
datagridview1.DataSource = Log_Table
If Log_Table.Rows.Count > 0 Then
    ' Log_Rec = Log_Table.First
    Dim Row As Telerik.WinControls.UI.GridViewRowInfo
    For Each Row In datagridview1.Rows
  
        If Row.Cells("Rec_ID").Value = RecID Then
            Row.IsSelected = True
            Row.IsCurrent = True
        Else
            Row.IsSelected = False
        End If
    Next
End If

This code will also invoke the ensure visible logic and will scroll the selected row into view.

I hope this will be useful. Should you have further questions, I would be glad to help.

Regards,
Ivan Petrov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
KawaUser
Top achievements
Rank 2
Answers by
Ivan Petrov
Telerik team
KawaUser
Top achievements
Rank 2
Share this question
or