Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi everyone..
am new in vb.net..
my problem is how to load my data to an arraylist and manually display it in the datagridview

sample table:
category table
-------------------------
| categoryid | category |
-------------------------
| 1 | category1 |
| 2 | category2 |
| 3 | category3 |
| 4 | category4 |
| 5 | category5 |
--------------------------

how can i store that to an array then extract the data in the array and
populate it in the datagridview

can anybody help me? plssss....

thanks in advance
Posted

Don't use an arraylist, create a DataTable instead and then you can just bind it to the datagridview. No mess, no fuss.
 
Share this answer
 
Comments
farout9999 14-Jul-11 12:21pm    
coz i manually set my grid header but when i tried to populate it ..it was change with fieldname

this is my code

<pre>
Private Sub populateGrid()
Dim msg As New clsMessage
Dim ds As New DataSet
Dim connectionString = New SqlConnection(getSqlConnectionString)
Dim strSQL As String
'Dim strColOrderBy As String
'Dim strColumns As String

Try
strSQL = "SELECT categoryid, category FROM category WHERE is_delete <> 1"

Using conn As New SqlConnection(getSqlConnectionString)
conn.Open()
Using adapterLib As New SqlDataAdapter(strSQL, connectionString)
adapterLib.Fill(ds, "category")
'dgMember.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.Raised
dgvCategory.DataSource = ds.Tables("category")
End Using
End Using
Catch ex As Exception
msg.setMessage = "Ooops, an unexpected error has been encountered." & Chr(13) & ex.Message
msg.setIcon = MessageBoxIcon.Warning
msg.setButton = MessageBoxButtons.OK
MessageBox.Show(msg.getMessage, "Error", msg.getButton, msg.getIcon)
msg = Nothing
End Try
End Sub
</pre>

did i get it right?
Abhinav S 14-Jul-11 12:48pm    
Sage advice. My 5.
thatraja 14-Jul-11 13:00pm    
Agree. The best one. 5!
This thread[^] might be useful to you.
 
Share this answer
 
Comments
farout9999 14-Jul-11 21:32pm    
sir how can i use this sample code so i could display my data in my grid.. thanks

<pre>
Private Sub PopulateDataGridView()

Dim row0 As String() = {"11/22/1968", "29", "Revolution 9", _
"Beatles", "The Beatles [White Album]"}
Dim row1 As String() = {"1960", "6", "Fools Rush In", _
"Frank Sinatra", "Nice 'N' Easy"}
Dim row2 As String() = {"11/11/1971", "1", "One of These Days", _
"Pink Floyd", "Meddle"}
Dim row3 As String() = {"1988", "7", "Where Is My Mind?", _
"Pixies", "Surfer Rosa"}
Dim row4 As String() = {"5/1981", "9", "Can't Find My Mind", _
"Cramps", "Psychedelic Jungle"}
Dim row5 As String() = {"6/10/2003", "13", _
"Scatterbrain. (As Dead As Leaves.)", _
"Radiohead", "Hail to the Thief"}
Dim row6 As String() = {"6/30/1992", "3", "Dress", "P J Harvey", "Dry"}

With Me.songsDataGridView.Rows
.Add(row0)
.Add(row1)
.Add(row2)
.Add(row3)
.Add(row4)
.Add(row5)
.Add(row6)
End With

With Me.songsDataGridView
.Columns(0).DisplayIndex = 3
.Columns(1).DisplayIndex = 4
.Columns(2).DisplayIndex = 0
.Columns(3).DisplayIndex = 1
.Columns(4).DisplayIndex = 2
End With

End Sub

</pre>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900