Solved

Two Listboxes problem??

Posted on 2006-11-05
6
178 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
  • 3
  • 3
6 Comments
 
LVL 62

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 62

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 62

Expert Comment

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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now