hi guys

I was wondering whether it is possible to load items to the data grid view without having to do it in the form load event. if so, please assist in discussing a few techniques.

thanks

When would you like it to load? It can be done on the click of a button, after a given time interval, at a specific time of day, when a file appears in a folder, etc.

There's no requirement that a DataGridView be initialized in the form Load event. Obviously you need to do it somewhere, but where kind of depends on the design of your application. Ideally it would happen in one of two places:

  1. Immediately before the user needs to see that information such as a button click event.

  2. In the background while the user is doing something else or being shown something else. This works best when the time to populate the grid is prohibitive.

Can you provide more details about the design of the application, the purpose of the grid, and how users will interact with it and its parent form?

This could really depends on when do you want to fill it, just as Jim had said. There are quite a number of ways you can achieve this. Could you tell us when do you wish to fill it?

hi

I already have an event in the form load which i use as the password picker. the data grid views are on different tab controls, but when I add the fill method for the data grid views under the form load the password picker method is skipped. that us my problem.

thanks.

datagrid view get data from a online MySQL/SQL server or local?

if is online for MySQL or SQL use this example

        Dim conn As SqlConnection
        Dim Command As SqlCommand
        Dim dbDataSet As New DataTable

        Dim SDA As New SqlDataAdapter

        Dim bSource As New BindingSource


       Private Sub load_table_Student()

            Dim conn As Data.SqlClient.SqlConnection
            conn = New Data.SqlClient.SqlConnection("Data Source=[Server IP, link or anything you have to connect with server];Network Library=DBMSSOCN;Initial Catalog=[Database name];User ID=[your ID];Password=[and password]")

            Try
                conn.Open()
                Dim Query As String
                Query = "SELECT * FROM Students"
                Command = New SqlCommand(Query, conn)
                SDA.SelectCommand = Command
                SDA.Fill(dbDataSet)
                bSource.DataSource = dbDataSet
                DataGridView1.DataSource = bSource

                conn.Close()

            Catch ex As SqlException
                MsgBox(ex.Message)
            Finally
                conn.Dispose()


            End Try
        End Sub

the code is on SQL Dataserver.
and it works for me very well

This is different between SQL and MySQL
in SQL is like this

 conn = New Data.SqlClient.SqlConnection("Data Source=[Server IP, link or anything you have to connect with server];Network Library=DBMSSOCN;Initial Catalog=[Database name];User ID=[your ID];Password=[and password]")

and MySQL is like

 Mysqlconn = New MySqlConnection
 Mysqlconn.ConnectionString = "server=db4free.net;Port=3306; user id=[your ID]; password=[and password]; database=[Database name]"

the rest is the some. (most of it, but have to change where is SqlCommand, change MySqlcommand. is pretty simple)

Edited 1 Year Ago by altjen

This article has been dead for over six months. Start a new discussion instead.