Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > Pro VB.NET 2002/2003
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Pro VB.NET 2002/2003 For advanced Visual Basic coders working .NET version 2002/2003. Beginning-level questions will be redirected to other forums, including Beginning VB.NET.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old November 14th, 2004, 07:52 AM
Registered User
 
Join Date: May 2004
Location: Mt. Gilead, Ohio, USA.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Contains method not working in items collection

I can not get the contains method to work - in the collection of objects I have in a list box. Is these a certain method I have to support in my object to make the contains method work?


Below is the code I am using to:
1) insert objects into the list (with the broken contains method)
.....[If Not lstDest.Items.Contains(objRef) Then <-- IS BROKEN]
2) the class definition for the objects I am adding


    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
            Handles btnAdd.Click, lstSource.DoubleClick
        ' Sunday, Nov 14, 2004: had to modify this routine to not add actUgrp's that are
        ' already in the dest list....
        '
        Dim intRelsAdded As Integer = 0
        Dim objRef As uGrpBaseRow
        Try
            Cursor.Current = Cursors.WaitCursor
            If lstSource.SelectedItems.Count > 1 Then lstDest.BeginUpdate()
            For Each objRef In lstSource.SelectedItems ' 1 or more baseUrows can be sel'ed
                If Not lstDest.Items.Contains(objRef) Then
                    lstDest.Items.Add(objRef)
                    intRelsAdded += 1
                End If
            Next
            If lstSource.SelectedItems.Count > 1 Then lstDest.EndUpdate()
            While lstSource.SelectedIndices.Count > 0
                'objRef =
                lstSource.Items.RemoveAt(lstSource.SelectedIndices (0))
            End While
            updateListCounts()
            RaiseEvent destListChanged_viaInternalBtn("Added (" & intRelsAdded & ") " & _
                                                    "relations to the current grouping...")
        Catch ex As Exception
                mObj4errhandling.writeError2log(ex)
                Throw New Exception(mObj4errhandling.seeEventLogErrNotice, ex)
        Finally
            Cursor.Current = Cursors.Default
        End Try
    End Sub

2) the class definition for the objects I am adding
Here's the objects I am adding to the list's items collection (they contain just a name
and a (unique) dbID:

Private Class uGrpBaseRow
        Inherits Object
        ' these sp names are for the user group table
Private mStrBaseRowName As String
        Private mIntBaseRowID As Integer

        Public Sub New(ByVal strBaseRowName As String, _
                        ByVal strBaseRowID As Integer)
            MyBase.new()
            mStrBaseRowName = strBaseRowName
            mIntBaseRowID = strBaseRowID
        End Sub
        ' need this method so the obj will display in the combo box..
        Public Overrides Function toString() As String
            Return mStrBaseRowName
        End Function
        Public ReadOnly Property name() As String
            Get
                Return mStrBaseRowName
            End Get
        End Property
        Public ReadOnly Property id() As Integer
            Get
                Return mIntBaseRowID
            End Get
        End Property
    End Class
#End Region

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
access of Items[""] collection in Httphandler anujrathi ASP.NET 2.0 Professional 0 November 15th, 2007 07:02 AM
Return Collection object from a Web Method raybo .NET Web Services 2 June 17th, 2006 07:42 AM
POST method not working ganesh15 Beginning PHP 2 February 18th, 2006 07:35 AM
Referencing Collection items by name rapatacs Pro VB.NET 2002/2003 0 March 16th, 2004 01:20 PM



All times are GMT -4. The time now is 08:15 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.