hi for my project what i am trying to do is:
i have two listboxes and in between the two boxes i have two buttons.

Btn1 is to send data from listbox1 to listbox 2
Btn2 is to send data from listbox2 to listbox1

below is my code could you please suggest improvements help me improve the method i am using thanks

Private Sub m_buttonAddUserRole_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles m_buttonAddUserRole.Click

    End Sub
    Sub connecta()
        acsconn.ConnectionString = "Provider=Microsoft.jet.oledb.4.0;data source=C:\Users\HP Sajad\Documents\Visual Studio 2010\Projects\login1\login1\security.mdb"

        If acsconn.State = ConnectionState.Open Then

        End If

        Dim roleIndex As Integer = ListBox1.SelectedIndex
        If (roleIndex = -1) Then
        End If
        ' Get the current user index.
        Dim userIndex As Integer = ListBox2.SelectedIndex
        ' Should we ignore the the event?
        If (userIndex = -1) Then
        End If

        ' Get the identifiers.
        Dim userID As Integer = CType(ListBox1.SelectedItem, Int32)
        Dim rightID As Integer = CType(ListBox2.SelectedItem, Int32)

        ' Search for an existing row.
        Dim rows As DataRow() = "Select right_id from cg_security_role_right where = '" & rightID & "' AND user_id = '" & userID & ;

        ' Is there already an association
        If (rows.Length > 0) Then
        End If

    End Sub
5 Years
Discussion Span
Last Post by Reverend Jim

1. Tell me one thing, how do you populate these 2 listBoxes?
Because so far I havent seen this code (and you actually didnt tell us).

2. And tell me one more thing, when some item is selected in listbox1, when you wanna transfer to listbox2, On which index do you wanna put it? On the same as it was in listBox1, or on last place?

Edited by Mitja Bonca: n/a


If the two listboxes have Sorted=True then

Private Sub btnAdd_Click(sender As System.Object, e As System.EventArgs) Handles btnAdd.Click

        If ListBox1.SelectedIndex >= 0 Then
        End If

    End Sub

    Private Sub btnRemove_Click(sender As System.Object, e As System.EventArgs) Handles btnRemove.Click

        If ListBox2.SelectedIndex >= 0 Then
        End If

    End Sub

You can add enhancements. For example, when an item is transfered, you might want to automatically select the next item so the user can repeatedly click "ADD" or "REMOVE" to transfer consecutive items. Or you could enable multiple selection.

Edited by Reverend Jim: n/a

Votes + Comments
Explained very easily...
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.