Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have this code that is load data to a datagridview in my first program when the user press the button to load the data to datagridview

It hangs for some second then they datagridview show all the records in the same time but I made this code to show to the user that the data is loading

But i have a problem when i press the button

the program show that the data is loading to datagridview but i can't press to any button in the form it's look like the form is freeze i want to use the backgroundworker but i don't know to use it can any one help me to populate the data into datagridview using backgroundworker and progress bar and using my code to show to the user that the data is loading
VB
Dim i As Integer = 0
    Dim sql As String
    connetionString = "Server=db4free.net;User Id=mouhcindinaoui;Password=dinaouimouhcin1991;Database=mouhcindinaoui"

    sql = "SELECT id,nom FROM dep02 "
    connection = New MySqlConnection(connetionString)
    Try

        connection.Open()
        Command = New MySqlCommand(sql, connection)
        reader = Command.ExecuteReader()


        If reader.HasRows Then
            Do While reader.Read()

                f1 = reader.GetString("id")
                f2 = reader.GetString("nom")

                DataGridView1.Rows.Add(New Object() {f1, f2})
                DataGridView1.Refresh()
                ' Me.DataGridView1.Rows(Me.DataGridView1.RowCount - 1).Selected = True
                DataGridView1.CurrentCell = DataGridView1(0, DataGridView1.Rows.Count - 1)
                Me.DataGridView1.FirstDisplayedScrollingRowIndex = Me.DataGridView1.RowCount - 1
                Thread.Sleep(10)
            Loop
        End If

        reader.Close()
        command.Dispose()
        connection.Close()
    Catch ex As Exception
        MsgBox("Can not open connection ! ")
    End Try
End Sub



if anyone can help me pleaseeeee write me a code
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900