Question CheckedListBox Query

Cenarkion

New member
Joined
Sep 1, 2010
Messages
1
Programming Experience
Beginner
Hi Guys, hoping you can help me out with a problem Im having with a checkedlistbox.

Just to be sure we are on the same page - I am an absolute novice, have managed to bumble my way through a few applications.

I am trying to put together a simple small application that will map a few network shares, depending on which ones are selected from the checked list box (about 22 possibilities).

Im not even sure I can get the box to do what I want, however I think it should.

Basically I want a list of drive names (not the UNC paths) that I can put a check next to and then hit a button and have them map (not interested in the mapping code, that I can do - I think).

I am struggling with getting the checked items to return data that I want. I can pull the index number or the simple drive name from the list box, however I was hoping that I could associate either of them with the actual usable data.

ie.

checkedlistbox

Drive 1
Drive 2
Drive 3
etc..

When selecting any of those a value that is not the index or the plain name be referenced instead (\\share\path).

I am doing this in Visual Studio 2010. Populating the checkedlistbox is a piece of cake, I just cant seem to find a way to convert the index number or the checkedname to the data that I can then work with to perform the required task.

I hope that makes some sense.

Once I can convert the plain name to an actual UNC path I should then be able to run a For loop to run through all of the selections and perform a network mapping operation on each of them. That is the plan at least.

Cena. :confused:
 
Hopefully this will help. The form has a CheckedListBox named CheckedListBox1 and a button named cmdList:

VB.NET:
Public Class TestCheckedListBox

    Public Class CheckedListBoxItem
        Public Property Name As String = String.Empty
        Public Property Value As String = String.Empty
        Public Sub New(ByVal theName As String, ByVal theValue As String)
            _Name = theName
            _Value = theValue
        End Sub
    End Class

    Private Sub Form_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        For i As Integer = 1 To 5
            CheckedListBox1.Items.Add(New CheckedListBoxItem("Drive " & i, "\\share\" & i))
        Next
        CheckedListBox1.DisplayMember = "Name"
        CheckedListBox1.ValueMember = "Value"
    End Sub

    Private Sub cmdList_Click(ByVal sender As System.Object, _
      ByVal e As System.EventArgs) Handles cmdList.Click
        Dim sb As New System.Text.StringBuilder("The following UNC paths were checked:" _
                                                 & Environment.NewLine)
        For Each clbi As CheckedListBoxItem In CheckedListBox1.CheckedItems
            sb.AppendLine(clbi.Value)
        Next
        MessageBox.Show(sb.ToString)
    End Sub

End Class
 
Back
Top