0

The following example shows how to Populate Data to DataGridView Control in VB.Net.


Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

With dgv
'SET COLUMN HEADERS
.Columns.Add("Product Code", "Product Code")
.Columns.Add("Product", "Product")
.Columns.Add("Quantity", "Quantity")
.Columns.Add("Price", "Price")

'START POPULATING DATA ROWS IN GRIDVIEW
For i As Integer = 0 To 100
.Rows.Add()
.RowHeadersVisible = False
.Item(0, i).Value = "PC121113 " & i
.Item(1, i).Value = "PRODUCT " & i
.Item(2, i).Value = 100 - i
.Item(3, i).Value = i
Next

.SelectionMode = DataGridViewSelectionMode.FullRowSelect
.BorderStyle = BorderStyle.Fixed3D
.BackgroundColor = Color.White
.RowsDefaultCellStyle.BackColor = Color.White
.AlternatingRowsDefaultCellStyle.BackColor = Color.WhiteSmoke
.AllowUserToResizeRows = False
End With

End Sub

End Class


Post a Comment

 
Top