none
Loading Form with DataGridView RRS feed

  • Question

  • I have a form that opens other forms, some of them as to get data from the Database, and when it does, it takes a while, what I want to do is to show a progress bar while it gets that data, instead of the program just being frozen
    Saturday, February 23, 2019 12:25 PM

All replies

  • Hello,

    Can you please show how the data is being loaded and use the code block button when doing this.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Saturday, February 23, 2019 1:15 PM
    Moderator
  • Hi,

    I made a demo, listview reads values from the database

    Imports System.Data.SqlClient
    Public Class Form1
        Dim constr As String = "Data Source = (localdb)\MSSQLLocalDB; Integrated Security = True ;AttachDbFileName= C:\Users\alexl2\Desktop\DataBase\Alex\alex.mdf"
        Dim conn As SqlConnection
        Dim cmd1 As SqlCommand
        Dim cmd2 As SqlCommand
        Dim dt As New DataTable
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Using conn = New SqlConnection(constr)
                conn.Open()
                cmd1 = New SqlCommand("Select count(*) From Student", conn)
                cmd2 = New SqlCommand("Select * From Student", conn)
                Dim count_all As Integer = Convert.ToInt32(cmd1.ExecuteScalar)
                ProgressBar1.Maximum = count_all
                Dim reader = cmd2.ExecuteReader
                While reader.Read
                    ProgressBar1.Value += 1
                    Application.DoEvents()
                    Dim lvi As New ListViewItem(reader.Item("Id").ToString)
                    lvi.SubItems.Add(reader.Item("Name").ToString)
                    ListView1.Items.Add(lvi)
                End While
            End Using
    
        End Sub
    End Class

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, February 25, 2019 7:59 AM