Solved

Two Listboxes problem??

Posted on 2006-11-05
6
182 Views
Last Modified: 2010-04-23
I have two ListBoxes in which I move items from Listbox1 to ListBox2 using DoubleClick on the item. I need to be able to check if the item is in Listbox2 then issue an error. But, my "If" statement below isn't working....

How would the "If" statement be coded???

Private Sub List1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles List1.DoubleClick
        If List1.SelectedIndex = List2.SelectedIndexCollection Then
            MsgBox("Server already exists")
     else
           LoadServer(List1.SelectedItem)
          CreateUMZ(List1.SelectedItem)
          Load_UMZBox1(List1.SelectedItem)
     End If
End Sub

thanks
0
Comment
Question by:rkckjk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 17876817
Hi rkckjk;

Try it this way.

    Private Sub List1_DoubleClick(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles List1.DoubleClick

        Dim AddItem As Boolean = True
        For Each List2Item As String In List2.Items
            If List1.SelectedItem Is List2Item Then
                AddItem = False
            End If
        Next

        If AddItem Then
            LoadServer(List1.SelectedItem)
            CreateUMZ(List1.SelectedItem)
            Load_UMZBox1(List1.SelectedItem)
        Else
            MsgBox("Server already exists")
        End If

    End Sub


Fernando
0
 
LVL 2

Author Comment

by:rkckjk
ID: 17876850
Actually I just figured it out and it works:

Private Sub List1_DoubleClick(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles List1.DoubleClick
     If List2.Items().Contains(List1.SelectedItem) Then
             MsgBox("Server already exists in the UMZ listing")
         Else
             LoadServer(List1.SelectedItem)
             CreateUMZ(List1.SelectedItem)
             Load_UMZBox1(List1.SelectedItem)
     End If
End sub

Your code didn't work, but anyway maybe you could answer a followup question that's related to this??

I'm also trying to check if the items are in Listbox2 from a MultiSelect option on ListBox1..


So, if the user highlights several items in ListBox1 and trys to add them to ListBox2, I don't want to add them if they're already in ListBox2...


thanks
0
 
LVL 2

Author Comment

by:rkckjk
ID: 17876855
I using the following code for MultiSelect:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim i As Integer
        Dim b As String
        For i = 0 To List1.SelectedItems.Count - 1
            If List2.Items().Contains(b) Then
                MsgBox("Server already exists in the UMZ listing")
            Else
                b = List1.SelectedItems(i).ToString
                LoadServer(b)
                CreateUMZ(b)
                Load_UMZBox1(b)
            End If
        Next
    End Sub
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 17876891
The first solution worked for me, anyway here is how to do the multiselected version. Jus move this line to where I placed it below.

    Private Sub Button1_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button1.Click

        Dim i As Integer
        Dim b As String
        For i = 0 To List1.SelectedItems.Count - 1
            b = List1.SelectedItems(i).ToString
            If List2.Items().Contains(b) Then
                MsgBox("Server already exists in the UMZ listing")
            Else
                LoadServer(b)
                CreateUMZ(b)
                Load_UMZBox1(b)
            End If
        Next

    End Sub

Fernando
0
 
LVL 2

Author Comment

by:rkckjk
ID: 17876899
That works great!!! thanks
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 17876919
Not a problem always glad to help. ;=)
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question