Getting the index from a collection 
Author Message
 Getting the index from a collection

Hello,

I'm trying to delete an item in a collection class.  The
user will click on an item in a list view control, choose
and then delete the corresponding item from the collection.

It would seem that the best way to do this would be to add
the index of each item in the collection to a hidden
column in the listview.  However, I can't figure out how
to retrieve this from the item in the collection.

Thanks,
Eric

The code is similar to the following:

Public NotInheritable Class Notes
Inherits CollectionBase

Public Sub Add(ByVal AppColl As Note)
Me.List.Add(AppColl)
End Sub

Public Sub Add(ByVal AppNotesText As String, ByVal
AppNotesUserName As String, ByVal AppNotesDate As Date)
Dim MyNote As Note
MyNote.NotesText = AppNotesText
MyNote.NotesDate = AppNotesDate
MyNote.NotesUserName = AppNotesUserName
Me.List.Add(MyNote)
End Sub

Public Sub Insert(ByVal Index As Integer, ByVal AppColl As
Note)
Me.List.Insert(Index, AppColl)
End Sub

Public Sub Remove(ByVal AppColl As Note)
Me.List.Remove(AppColl)
End Sub

Default Public Property Item(ByVal Index As Integer) As
Note
Get
Return DirectCast(Me.List.Item(Index), Note)
End Get
Set(ByVal Value As Note)
Me.List.Item(Index) = Value
End Set
End Property

End Class

Public Class Note
Public NotesText As String
Public NotesUserName As String
Public NotesDate As Date

Public Sub New(ByVal AppNotesText As String, ByVal
AppNotesUserName As String, ByVal AppNotesDate As Date)
Me.NotesText = AppNotesText
Me.NotesUserName = AppNotesUserName
Me.NotesDate = AppNotesDate
End Sub

End Class

Private Sub PopulateNotesListView()
 Dim MyNote As Note
 Dim ItemEntry As New ListViewItem()

 Try

lsvNotes.Items.Clear()

Private Sub PopulateNotesListView()
Dim MyNote As ApproNote
Dim ItemEntry As New ListViewItem()

Try

lsvNotes.Items.Clear()

For Each MyNote In mLoanApp.ApproNotesList
'Add to listview
ItemEntry = lsvNotes.Items.Add(MyNote.ApproNotesUserName)
ItemEntry.SubItems.Add(MyNote.ApproNotesDate.ToString)
ItemEntry.SubItems.Add(MyNote.ApproNotesText)
'I WOULD LIKE TO HAVE CODE TO ADD THE INDEX OF
'MYNOTE HERE, BUT CAN'T FIGURE OUT HOW TO GET TO IT.
Next

Catch exp As Exception
ExceptionHandler.ErrHandler
("frmLoanApplication.PopulateNotesListView", exp)
End Try

End Sub



Sat, 17 Sep 2005 07:18:02 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Indexes collection contains more indexes that I created????

2. Finding indexes of controls in controls collection

3. return the index number of an object in a collection

4. How to get table's index in the tables collection

5. Changing index # of items in Controls Collection

6. Index and Key Collections

7. Indexes Collection - Why is it empty?

8. Get Collection Index val from Key

9. How is indexing done in collections?

10. Retrieve Key and Index in Collections?

11. Problems removing items from collection by index

12. INDEXED COLLECTIONS: Possible?

 

 
Powered by phpBB® Forum Software