whats wrong with my code?

I love vb

New member
Joined
Nov 1, 2011
Messages
3
Programming Experience
1-3
Hello
I write some code that opens a database then list's the tables then if you click on the table it will list the columns in the table along with the
data i have every thing working but all the data lists in the first column if the list view as seen in the image bellow.

Thanks so much for your help :)

Code that gets and lists data/columns :
VB.NET:
[LEFT][COLOR=#CCCCCC][FONT=Monaco]public Sub list_data(ByRef Table As String, ByRef loction As String)[/FONT][/COLOR]
[COLOR=#CCCCCC][FONT=Monaco]  'ListView1.Columns.Clear()[/FONT][/COLOR]
[COLOR=#CCCCCC][FONT=Monaco]  Dim connection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & loction)[/FONT][/COLOR]
[COLOR=#CCCCCC][FONT=Monaco]  connection.Open()[/FONT][/COLOR]
[COLOR=#CCCCCC][FONT=Monaco]  Dim da As New OleDb.OleDbDataAdapter("select * from " & Table, connection)[/FONT][/COLOR]
[COLOR=#CCCCCC][FONT=Monaco]  Dim ds As New DataSet[/FONT][/COLOR]
[COLOR=#CCCCCC][FONT=Monaco]  da.Fill(ds)[/FONT][/COLOR]
[COLOR=#CCCCCC][FONT=Monaco]  For a = 0 To ListView1.Columns.Count - 1[/FONT][/COLOR]
[COLOR=#CCCCCC][FONT=Monaco]    For i = 0 To ds.Tables(0).Rows.Count - 1[/FONT][/COLOR]
[COLOR=#CCCCCC][FONT=Monaco]    ListView1.Columns(a).ListView.Items.Add(ds.Tables(0).Rows(i)(a))[/FONT][/COLOR]
[COLOR=#CCCCCC][FONT=Monaco]    Next i[/FONT][/COLOR]
[COLOR=#CCCCCC][FONT=Monaco]  Next[/FONT][/COLOR]

[COLOR=#CCCCCC][FONT=Monaco]    End Sub[/FONT][/COLOR][/LEFT]

Image
help.jpg
 

Attachments

  • icon9.png
    icon9.png
    738 bytes · Views: 39
What's wrong is that you are only adding items and no subitems. When you add an item, the text you specify is displayed in the first column. If you want text in another column of the same row then you have to add subitems to that item.

I shouldn't really have to say this because it's something that everyone should without any prompting but you should start by reading the documentation for the ListView class. It includes a code example that, amongst other things, adds items and subitems.
 
Back
Top