# CheckedListbox Items into array?



## <<Onafets>> (Jun 6, 2011)

Hey guys, I solved my problem earlier abour getting folder names into the list box using this code:

```
Dim info As DirectoryInfo = New DirectoryInfo(saves)
CheckedListBox1.DataSource = info.GetFileSystemInfos()
```

But now I need help dumping only the checked items in the checked listbox into an array.

What im trying to do when the button is pressed is:

Dump Checked items to array
Get Item number 0 (becuase arrays start at 0 yes?)
Add string to item 0
Then copy some crap using info gathered from string
Uncheck Item 0 from list box
Re dump checked items to array and loop cycle until no items left checked.

Any ideas? (Note i only need help with the dumping of araay at this point )
This is VB .net btw
Cheers Ona


----------



## streetfighter 2 (Jun 6, 2011)

Did you check the documentation for the methods/properties you need?  I'm guessing you're using the CheckedListBox class.

Here's the CheckedItems property.
The GetItemChecked method.


----------



## FordGT90Concept (Jun 6, 2011)

Yeah, and use a for-loop to copy the values into an array.


----------



## CrackerJack (Jun 6, 2011)

Sample, This return Files/Folders

```
Dim info As DirectoryInfo = New DirectoryInfo(saves)
        CheckedListBox1.DataSource = info.GetFileSystemInfos()
        For Each item In info.GetFileSystemInfos()
            CheckedListBox1.Items.Add(item)
        Next
```

Sample, This will return Folders

```
Dim info As DirectoryInfo = New DirectoryInfo(saves)
        For Each item In info.GetDirectories
            CheckedListBox1.Items.Add(item)
        Next
```


----------



## Kreij (Jun 6, 2011)

Assuming your CheckedListBox is named "clb" ...


```
ArrayList myArray = new ArrayList();
foreach (object checkedItem in clb.CheckedItems)
{
    // Add to the array
    myArray.Add(checkedItem.ToString());
    // uncheck it
    clb.SetItemCheckState(clb.Items.IndexOf(checkedItem), CheckState.Unchecked);
}

... do more stuff ...
```

Should be easy enought to port to VB


----------

