• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.
  • The forums have been upgraded with support for dark mode. By default it will follow the setting on your system/browser. You may override it by scrolling to the end of the page and clicking the gears icon.

CheckedListbox Items into array?

Joined
Nov 8, 2008
Messages
779 (0.13/day)
Location
Sydney, Australia
System Name Gearbox || Server
Processor i5 3570K @ 4.0Ghz || E8400 @ Stock 3Ghz
Motherboard Gigabyte Z68XP-UD3 || Gigabyte EP41-UD3L
Cooling Stock || Stock
Memory 8GB G.Skill RipjawX DDR3 @ 1600mhz || 4GB Kingston Value DDR2 800Mhz
Video Card(s) ASUS R9 270X Direct CU II TOP @ 1120/1500 || N/A
Storage Samsung 840 EVO 250GB || 1TB WD Green, 2TB WD Green, 3TB WD Red
Display(s) HP x23 LED 23" Full HD Panel
Case Corsair 200R || Open-Air
Audio Device(s) Audioengine D1 + Logitech Z623/Audio Technica ATH-M50 || N/A
Power Supply Antec EarthWatts Platinum 650 W || Antec Neo Eco 450 W
Software Windows 8.1 Update 3 Pro 64 || Ubuntu Server 14.04 64
Hey guys, I solved my problem earlier abour getting folder names into the list box using this code:
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:
  1. Dump Checked items to array
  2. Get Item number 0 (becuase arrays start at 0 yes?)
  3. Add string to item 0
  4. Then copy some crap using info gathered from string
  5. Uncheck Item 0 from list box
  6. 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
 
Yeah, and use a for-loop to copy the values into an array.
 
Sample, This return Files/Folders
Code:
 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
Code:
 Dim info As DirectoryInfo = New DirectoryInfo(saves)
        For Each item In info.GetDirectories
            CheckedListBox1.Items.Add(item)
        Next
 
Last edited:
Assuming your CheckedListBox is named "clb" ...

Code:
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 ;)
 
Back
Top