dcsimg
Results 1 to 7 of 7

Thread: Scroll to middle of datagridview

  1. #1

    Thread Starter
    Frenzied Member schoemr's Avatar
    Join Date
    Apr 2016
    Location
    South Africa
    Posts
    1,081

    Scroll to middle of datagridview

    Hi, I am not sure how to ask this, let alone google this...


    I have a datagridview that is almost the size of entire form.

    I 'edit' details and save and to "to get back" to the row that was edit I do this:

    When the edit button is press I get the current row

    Code:
      currentRow = Me.TblUsersBindingSource.Position
    Then after the save routine I get back to that row:

    Code:
    Me.TblUsersBindingSource.Position = currentRow
    The problem is that the row scroll then to bottom (of the datagridview)

    It is the correct row, but I don't want it must be at the bottom of what is visible...

    Name:  1.JPG
Views: 116
Size:  21.8 KB

    I want that current row must be vertically in the center of the datagridview (there can be rows more on top and also more rows below..

    It is not that the row is now at the bottom of all the rows... It is at the bottom of the "current view"...

    I hope someone can understand what I mean...

    Name:  2.JPG
Views: 115
Size:  25.0 KB
    Don't miss the whole point of the dance...

    https://www.youtube.com/watch?v=qHnIJeE3LAI

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,754

    Re: Scroll to middle of datagridview

    I would have thought that you'd need to do anything as the grid should just stay as it was. My guess is that you're resetting the DataSource property, which you definitely shouldn't be doing. My extended guess is that you're doing what so many people do: you open a dialogue to edit data, save to the database from that dialogue and then requery to get the new data. That is the wrong approach. Can you confirm or deny that that is what you're doing? If it's not what you're doing, can you show us what you are doing.

  3. #3

    Thread Starter
    Frenzied Member schoemr's Avatar
    Join Date
    Apr 2016
    Location
    South Africa
    Posts
    1,081

    Re: Scroll to middle of datagridview

    Hi John,

    My extended guess is that you're doing what so many people do: you open a dialogue to edit data, save to the database from that dialogue and then requery to get the new data. That is the wrong approach.

    Yes that is exactly what I am doing.

    After I edit textboxes then I save like so:

    Code:
    Me.Validate()
            Me.TblUsersBindingSource.EndEdit()
            Me.TblUsersTableAdapter.Update(Me.RiskDBDataSet.TblUsers)
    
    
            're query
    
            If MyGlobalVariableUserType = CStr("Admin") Then
                Me.TblUsersTableAdapter.FillByAdminsBusiness(Me.RiskDBDataSet.TblUsers, MyGlobalVariableUsersBusiness)
               
            End If
    
            If MyGlobalVariableUserType = CStr("Super User") Then
                Me.TblUsersTableAdapter.Fill(Me.RiskDBDataSet.TblUsers)
                       End If
    But I don't edit the DGV itself.... I have textboxes also on the form.. I edit the textboxes (it correspond to the dgv - meaning I drag the 'details' and dgv to form...

    Name:  1.JPG
Views: 31
Size:  26.1 KB
    Last edited by schoemr; Aug 5th, 2019 at 09:37 AM.
    Don't miss the whole point of the dance...

    https://www.youtube.com/watch?v=qHnIJeE3LAI

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,754

    Re: Scroll to middle of datagridview

    Then you're doing it wrong. You use the table adapter to populate the DataTable and bind that to the grid. When you edit the data, you make changes to the data in that DataTable. That will inherently update the bound grid. You then use the same table adapter to save the changes from the DataTable back to the database. It's silly to requery the database to get data that you already have and it also means that you don't have to fix problems like this one.

  5. #5

    Thread Starter
    Frenzied Member schoemr's Avatar
    Join Date
    Apr 2016
    Location
    South Africa
    Posts
    1,081

    Re: Scroll to middle of datagridview

    John, thank you for your reply...

    Are you saying what I am do wrong or are you saying what I am supposed to be doing?
    Don't miss the whole point of the dance...

    https://www.youtube.com/watch?v=qHnIJeE3LAI

  6. #6

    Thread Starter
    Frenzied Member schoemr's Avatar
    Join Date
    Apr 2016
    Location
    South Africa
    Posts
    1,081

    Re: Scroll to middle of datagridview

    Okay, I think I understand...

    I don't need to fill the tableadapter again after saving....

    I don't know why I did this
    Don't miss the whole point of the dance...

    https://www.youtube.com/watch?v=qHnIJeE3LAI

  7. #7
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    4,171

    Re: Scroll to middle of datagridview

    Quote Originally Posted by schoemr View Post
    Okay, I think I understand...

    I don't need to fill the tableadapter again after saving....

    I don't know why I did this
    You don't fill a TableAdapter, you fill a DataTable. Think about it, you just sent what was in the DataTable to the database with the Update method. So what is in the database matches what is in the Datatable, so what good does filling the datatable do? Unless you didn't retrieve all the records on the initial fill and for some reason now you want to retrieve all the records.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width