Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listview

Status
Not open for further replies.

MDA

Technical User
Jan 16, 2001
243
US
Does anyone know if it is possible to Add/delete or change a subitem in a specific column?

I have found no reference to how this can be done.

Example:
A listview contains three columns. The first column contains "item1" I want to add a subitem to column three. Is this possible? I do NOT want to add a subitem to column two, only column three. It seems that subitems are added from Left - right. Anyway aroung this in .net?

Any clues??
M
 
Think of the collection of ListViewItems as representing column 0. Each ListViewSubItem, 1 thru n, attached to a ListViewItem represents columns 1 thru n.

Column 0 Col 1 Col 2
ListViewItem(0)-->ListViewSubitem(0) ListViewSubitem(1)
ListViewItem(1)-->ListViewSubItem(0) ListViewSubItem(1)

listView1.Columns are used for Headers alignment etc of the ListViewItem and the attached ListViewSubItems.

Forms/Controls Resizing/Tabbing
Compare Code
Generate Sort Class in VB
Check To MS)
 
Thanks John,

So do you have an example of adding a subitem to column 2 for instance, without adding anything to column 1? Because I have not been able to find any .net reference that shows how this is possible.

For example I can use:
ListView1.Items(1).SubItems.Add("Mydata")

That will add Mydata in the first available subitem for item index 1 (this is not what I want)

If I try:

listview1.Items(1).SubItems(2).???
[There is no ADD allowed with this syntax] So how do I refer to the specific column.

I must be missing something!!

Thanks again,
M
 
I am not sure I can untangle your view. Here is code that I used to display a Listview of File data contained in parallel arrays.
Imports System.Windows.Forms
......
Dim ColumnHeaders As ListView.ColumnHeaderCollection
Dim ColumnHeader As ListView.ColumnHeader
With ZipListView
.Clear()
.BeginUpdate()
.MultiSelect = True
If mlngFilename < 0 Then Exit Sub
ColumnHeaders = .Columns
End With
With ColumnHeaders
.Add("Name", -1, HorizontalAlignment.Left)
.Add("Date Modified", -1, HorizontalAlignment.Left)
.Add("Size", -1, HorizontalAlignment.Right)
.Add("Path", -1, HorizontalAlignment.Left)
End With

Dim objItems As ListView.ListViewItemCollection
Dim objItem As ListViewItem

objItems = ZipListView.Items
For I = 0 To maryFileName.GetUpperBound(0)
' Add New Item to list, col 0
objItem = objItems.Add(maryFileName(I))
' add subitems (columns?)( to returned item, cols 1 - 4
With objItem
.SubItems.Add(maryDateTime(I))
.SubItems.Add(marySize(I).ToString)
.SubItems.Add(maryPathName(I))
End With
Next
ZipListView.EndUpdate()


Forms/Controls Resizing/Tabbing
Compare Code
Generate Sort Class in VB
Check To MS)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top