Listview add items?

  • Thread starter Thread starter Able
  • Start date Start date
A

Able

Dear friends

Items is added like this

Dim itmx As New ListViewItem

itmx = ListView1.Items.Add("Title", 0)

itmx.SubItems.Add("1")

itmx.SubItems.Add("2")

itmx.SubItems.Add("3")

The item "2" is added in row one in second column and "3" is added in row
one in third column. But is it possible to add item "2" in row one in third
column and add "3" in row one in second column without rearranging the
sequence in designtime. In other words is it possibly to programaticly
determine the column?



Regards Able
 
There are some possibilities:

'Create empty subitems and fill them
Dim i As ListViewItem = ListView1.Items.Add("Test")
i.SubItems.Add(String.Empty)
i.SubItems.Add(String.Empty)
i.SubItems.Add(String.Empty)
i.SubItems(3).Text = "3"
i.SubItems(2).Text = "2"
i.SubItems(1).Text = "1"

'Use temp. variables
Dim j As ListViewItem = ListView1.Items.Add("Test")
Dim a, b, c As String
a = "1"
b = "2"
c = "3"
j.SubItems.AddRange(New String() {c, b, a})
 
Superb.

Able


Jan Tielens said:
There are some possibilities:

'Create empty subitems and fill them
Dim i As ListViewItem = ListView1.Items.Add("Test")
i.SubItems.Add(String.Empty)
i.SubItems.Add(String.Empty)
i.SubItems.Add(String.Empty)
i.SubItems(3).Text = "3"
i.SubItems(2).Text = "2"
i.SubItems(1).Text = "1"

'Use temp. variables
Dim j As ListViewItem = ListView1.Items.Add("Test")
Dim a, b, c As String
a = "1"
b = "2"
c = "3"
j.SubItems.AddRange(New String() {c, b, a})


--
Greetz,
Jan
__________________________________
Read my weblog: http://weblogs.asp.net/jan
 
* "Able said:
Items is added like this

Dim itmx As New ListViewItem

itmx = ListView1.Items.Add("Title", 0)

itmx.SubItems.Add("1")

itmx.SubItems.Add("2")

itmx.SubItems.Add("3")

The item "2" is added in row one in second column and "3" is added in row
one in third column. But is it possible to add item "2" in row one in third
column and add "3" in row one in second column without rearranging the
sequence in designtime. In other words is it possibly to programaticly
determine the column?

Just asking: Why? You may want to have a look at the 'Insert' method
instead of using 'Add' (untested).
 
Not a single item on Google refering to the insert method.

Please give an example.

Regards Able
 
* "Able said:
Not a single item on Google refering to the insert method.

Please give an example.

Really crippled code:

\\\
With Me.ListView1.Items(0).SubItems
.Add("aa")
.Add("bb")
.Insert(2, New ListViewItem.ListViewSubItem(Nothing, "bb"))
End With
///
 
Back
Top