DataGridView adding rows and columns in VB.NET

The DataGridView control in Windows Forms is a comprehensive solution specifically designed for displaying tabular data. It offers extensive customization options through its wide range of properties, methods, and events, allowing developers to tailor its appearance and behavior to suit their needs. The flexibility of the DataGridView control enables it to seamlessly display data from various external sources.

Moreover, the control provides the option to manually populate it with data by programmatically adding rows and columns. This allows for complete control over the data displayed within the DataGridView. Developers have the freedom to define the structure of the DataGridView by creating and configuring columns, as well as populating it with data in a row-by-row manner.

To illustrate this, the following VB.NET source code demonstrates the process of manually creating columns and rows in a DataGridView. By utilizing the DataGridView's functionality, developers can programmatically define the columns and populate them with data according to their specific requirements.

DataGridView1.Columns(Index).Name = "Column Name".

Full Source VB.NET
Imports System.Data.SqlClient Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click DataGridView1.ColumnCount = 3 DataGridView1.Columns(0).Name = "Product ID" DataGridView1.Columns(1).Name = "Product Name" DataGridView1.Columns(2).Name = "Product_Price" Dim row As String() = New String() {"1", "Product 1", "1000"} DataGridView1.Rows.Add(row) row = New String() {"2", "Product 2", "2000"} DataGridView1.Rows.Add(row) row = New String() {"3", "Product 3", "3000"} DataGridView1.Rows.Add(row) row = New String() {"4", "Product 4", "4000"} DataGridView1.Rows.Add(row) End Sub End Class