displaying custom column in a DataGridView

buffdaemon_live

New member
Joined
Jun 13, 2008
Messages
3
Programming Experience
Beginner
HI all,
I have a problem while displaying the data in the DataGridView using my custom column name
below is my code. I wanted to display the data in rows under the column like this:
ID Name
--- ------
1 silk
2 milk

Below is my source code:


VB.NET:
Dim objG As New systemClass

Dim sqlCon As SqlConnection

sqlCon = objG.dbSConnect

Dim SQL As String = "select id,name from products"

Dim da As New SqlDataAdapter(SQL, sqlCon)

Dim dt As New DataTable

da.Fill(dt)

"dgvInstructors" is my DataGridView name

VB.NET:
Me.dgvInstructors.ColumnCount = 2

Me.dgvInstructors.ColumnHeadersVisible = True

Dim columnHeaderStyle As New DataGridViewCellStyle

Me.dgvInstructors.ColumnHeadersDefaultCellStyle = columnHeaderStyle

'set the column header names

Me.dgvInstructors.Columns(0).Name = "ID"

Me.dgvInstructors.Columns(1).Name = "Name"

Me.dgvInstructors.Rows.Add(dt)



Please help me with this.
 
Given that youre using .NET 2 I cant understand why you'd do this manually. You should take a read of the DW2 link in my signature, section on "creating a simple data app"
 

Latest posts

Back
Top