Datagridview ROWHEADER position after refresh Grid

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • iqbalnazim
    New Member
    • Oct 2012
    • 5

    #1

    Datagridview ROWHEADER position after refresh Grid

    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!

    Code:
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    
    '' SCROLLING POSITION BEFORE REFRESH
    MaintainScrollPosition.GetSBarPos(DataGridView1)
    
    DataGridView1.DataSource = Get_records()
        
    '' SCROLLING POSITION AFTER REFRESH
    MaintainScrollPosition.SetSBarPos(DataGridView1)
    
    '' SELECTED RECORD POSITION
    DataGridView1.Rows(iTopRow).Selected = True
    
    Call gridcolor()
    End Sub
    
    '' DATA REFRESH FUNCTION
    Public Function Get_records() As Data.DataTable
    
    Dim col As Integer = DataGridView1.CurrentCell.Selected
    Dim row As Integer = DataGridView1.CurrentRow.Selected
    
    Try
    
    Dim sSQL As String = "Select ddd from ddd"
    Dim myDA As New MySqlDataAdapter(sSQL, conn)
    Dim dsData As New DataSet()
    
    myDA.Fill(dsData, "tblcurrentrundown")
    Return dsData.Tables("tblcurrentrundown")
    
    'NOT WORKING---set the grid back the the first cell displayed
    DataGridView1.FirstDisplayedCell = DataGridView1.Item(col, row)
    
    conn.Close()
    Catch ex As Exception
    conn.Close()
    Throw
    Finally
    conn.Close()
    
    End Try
    
    End Function
    Attached Files
Working...