Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > Pro VB.NET 2002/2003
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 14th, 2004, 08:52 AM
Registered User
 
Join Date: May 2004
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






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 08: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 08:35 AM
Referencing Collection items by name rapatacs Pro VB.NET 2002/2003 0 March 16th, 2004 02:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.