开发者

How to display records in the listview control?

I'm trying to use listview control in vb.net or vb2008 express edition to display records from my database after it is being queried.I have two column headers in my listview control which are named Account# and Authorized Users. I was able to display the records from the database into the listview control but i don't know how to arrange it in a proper column where it should be displayed cause what happen is all records are being combined in one column which other records should be aligned to the other column.What I want is to display the account numbers in aligned with the Account# column header and the names should be aligned in Authorized Users column header. Here's the codes I used:

*****************************************************************
Private Sub Button1_Click(-------------) Handles Button1.Click

     Dim db As New memrecDataContext
     Dim au = From ah In db.Table1s _
               Where ah.Account <> " "

     For Each ah In au
          With Form9.ListView1.Items
                 Form9.ListView1.Items.Add(ah.Account)
                 Form9.L开发者_Python百科istView1.Items.Add(ah.Name)
                 Form9.Show()
          End With
    Next

End Sub
*********************************************************

I would greatly appreciate if you could correctly debug the codes for me?


In listview, details mode, both columns are in a single listview item. The first column is item.text, and the rest are in item.subitems, something like this:

dim item as ListViewItem
ListView1.Columns.Add("Account")
ListView1.Columns.Add("Name")

For Each ah In au
  item = New ListViewItem
  item.text = ah.Account
  item.subitems.add(ah.Name)
  form9.listview1.items.add(item)
  next ah

A couple of notes: You should not show the form every time you add an item to the listview. You're better off showing the form only once. Second, the With statement is used to shortcut writing form9.listview.items. Inside the With block you can use just a period (.) instead of writing out form9.listview.items.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜