By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,902 Members | 1,268 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,902 IT Pros & Developers. It's quick & easy.

Datagridview ROWHEADER position after refresh Grid

P: 5
I am facing this problems in my project!

I have a DATAGRIGVIEW1 which is refreshing in every 10 sec. to update records.

After refreshing the ROWHEADER (Left Black pointer or record Indicator) move to first Record, but my ROW is selected, only ROWHEADER goes up which create a problem by clicking NEXT button.

I am NEW here don't know to allow to paste code or not!

Expand|Select|Wrap|Line Numbers
  1. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  2.  
  3. '' SCROLLING POSITION BEFORE REFRESH
  4. MaintainScrollPosition.GetSBarPos(DataGridView1)
  5.  
  6. DataGridView1.DataSource = Get_records()
  7.  
  8. '' SCROLLING POSITION AFTER REFRESH
  9. MaintainScrollPosition.SetSBarPos(DataGridView1)
  10.  
  11. '' SELECTED RECORD POSITION
  12. DataGridView1.Rows(iTopRow).Selected = True
  13.  
  14. Call gridcolor()
  15. End Sub
  16.  
  17. '' DATA REFRESH FUNCTION
  18. Public Function Get_records() As Data.DataTable
  19.  
  20. Dim col As Integer = DataGridView1.CurrentCell.Selected
  21. Dim row As Integer = DataGridView1.CurrentRow.Selected
  22.  
  23. Try
  24.  
  25. Dim sSQL As String = "Select ddd from ddd"
  26. Dim myDA As New MySqlDataAdapter(sSQL, conn)
  27. Dim dsData As New DataSet()
  28.  
  29. myDA.Fill(dsData, "tblcurrentrundown")
  30. Return dsData.Tables("tblcurrentrundown")
  31.  
  32. 'NOT WORKING---set the grid back the the first cell displayed
  33. DataGridView1.FirstDisplayedCell = DataGridView1.Item(col, row)
  34.  
  35. conn.Close()
  36. Catch ex As Exception
  37. conn.Close()
  38. Throw
  39. Finally
  40. conn.Close()
  41.  
  42. End Try
  43.  
  44. End Function
  45.  
  46.  
  47.  
Attached Images
File Type: jpg 02-Datagridview1-After-Refr.jpg (119.9 KB, 85 views)
File Type: jpg 01-Datagridview1-Before-Ref.jpg (116.5 KB, 88 views)
Nov 20 '12 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.