2

I'm pretty new to VB.net and I'm trying to figure out how to add multiple columns of data to a listview.

After searching several different sources, I think this is the way I should be doing it:

address.Columns.Add("address1", 200, HorizontalAlignment.Left)
address.Columns.Add("address2", 100, HorizontalAlignment.Left)
address.Columns.Add("city", 100, HorizontalAlignment.Left)

Dim AddressData(2) As String
Dim AddressLine As ListViewItem
AddressData(0) = "123 fake st"
AddressData(1) = "unit 1"
AddressData(2) = "fakecity"
AddressLine = New ListViewItem(AddressData)
address.Items.Add(AddressLine)

But for some reason, the list view only shows one column displaying "123 fake st", and it seems to be completely ignoring any changes to column width. What am I doing wrong?

  • You have to change the View property to "Details" – The One Jan 08 '15 at 13:28
  • address.View = View.Details – The One Jan 08 '15 at 13:28
  • Make sure View is set to Details. Columns can be added via the Design UI along rather than in code – Ňɏssa Pøngjǣrdenlarp Jan 08 '15 at 13:29
  • @Steven Doggart Could you please share with me the question of which this is a duplicate? I did try my best to search other questions prior to posting but found no solutions to my problem. – exceptional exception Jan 08 '15 at 14:12
  • The link to the duplicate question is actually already shown above your question. It's no problem. I appreciate that you searched to try to find another duplicate first. Some people don't bother to do that. However, sometimes it's tough to find the existing duplicates if they are worded differently than what precisely you are searching for. With that in mind, having duplicate questions, each worded differently in their own way, can actually be a good thing. That's why the duplicate questions are kept around for future people to find via searches using your terminology. It's all good :) – Steven Doggart Jan 08 '15 at 14:25
  • Thanks! :) It's nice to know "Duplicate Question" isn't necessarily a bad thing. – exceptional exception Jan 08 '15 at 14:27
  • Yup. It's only a bad thing if it happens all the time and the questions are all worded almost exactly the same. Then it can be annoying. But in a case like this, I don't think anyone would frown upon it at all. Thanks for taking time to contribute to the site. I see that you've even answered as many questions as you've asked. That kind of thing doesn't go unnoticed by your fellow users :) – Steven Doggart Jan 08 '15 at 14:33

2 Answers2

3

You have to set the View Property to "Details"

address.View = View.Details
The One
  • 4,560
  • 5
  • 36
  • 52
1

Select your listview and you can see an arrow in the top left corner of the control. Click it and press "Edit Columns". That should do the trick.

CodingSource
  • 203
  • 2
  • 15