Solved

Two Listboxes problem??

Posted on 2006-11-05
6
183 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

724 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