Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > DataGridView Does Not Show Vertical ScrollBar
 

DataGridView Does Not Show Vertical ScrollBar

Hi,

I'm filling a datagridview with a DataTable, it worked fine but since I started using a thread to fill it, DataGridView does not show the vertical scrollbar, has anybody solved this ?

Private LoadOrdersThread As New Thread(New ThreadStart(AddressOf LoadOrders))

Private Sub frmTicket_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
LoadOrdersThread.Start()
End Sub

Private Sub LoadOrders()
dgOrders.DataSource = DRSLoadOrders (datatable)
LoadOrdersThread.Abort()
End Sub




George Waters  Tuesday, September 08, 2009 9:38 AM
Well, I finally found the solution for those with the same problem.

When using threads, the thread cannot access UI because UI it wasn't created by the thread. In this case we have to use Delegate and Invoke, here's how the above code works ok and now the vertical bar appears:

Private Delegate Sub Conect_Delegate(ByVal dg As DataGridView, ByVal Table As DataTable)
Private Orders As New DataTable
Private LoadOrdersThread As New Thread(New ThreadStart(AddressOf LoadOrders))

 Private Sub frmTicket_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        LoadOrdersThread.Start()
 End Sub

 Private Sub LoadOrders()
        Orders = MyFunctionToFillDataTable
        If dgvOrders.InvokeRequired Then
            dgvOrders.Invoke(New Conect_Delegate(AddressOf Conect), dgvOrders, Orders)
        End If
        LoadOrdersThread.Abort()
End Sub

 Private Sub Conect(ByVal dgv As DataGridView, ByVal xTable As DataTable)
        dgv.DataSource = xTable
End Sub

Hope it helps !!!

  • Marked As Answer byGeorge Waters Tuesday, September 08, 2009 8:54 PM
  •  
George Waters  Tuesday, September 08, 2009 8:52 PM
Well, I finally found the solution for those with the same problem.

When using threads, the thread cannot access UI because UI it wasn't created by the thread. In this case we have to use Delegate and Invoke, here's how the above code works ok and now the vertical bar appears:

Private Delegate Sub Conect_Delegate(ByVal dg As DataGridView, ByVal Table As DataTable)
Private Orders As New DataTable
Private LoadOrdersThread As New Thread(New ThreadStart(AddressOf LoadOrders))

 Private Sub frmTicket_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        LoadOrdersThread.Start()
 End Sub

 Private Sub LoadOrders()
        Orders = MyFunctionToFillDataTable
        If dgvOrders.InvokeRequired Then
            dgvOrders.Invoke(New Conect_Delegate(AddressOf Conect), dgvOrders, Orders)
        End If
        LoadOrdersThread.Abort()
End Sub

 Private Sub Conect(ByVal dgv As DataGridView, ByVal xTable As DataTable)
        dgv.DataSource = xTable
End Sub

Hope it helps !!!

  • Marked As Answer byGeorge Waters Tuesday, September 08, 2009 8:54 PM
  •  
George Waters  Tuesday, September 08, 2009 8:52 PM

You can use google to search for other answers

Custom Search

More Threads

• Double click the row in the datagriview in order to open the program "notepad.exe", when the entire row is selected.
• Datagrid Parent/Child Relationships and Index out of Range Exception
• DataBind ComboBox DataSource On The Fly
• Combobox use in visual studio
• embedded datagrids
• Searching a Datagrid problem! (ADO)
• Changes in database and update datagridview problem
• Merging of cells in datagridview control
• DataGridView update to database
• How to add duplicate datacolumn to datatable