• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

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
 

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,263 (4.35/day)
Location
IA, USA
System Name BY-2021
Processor AMD Ryzen 7 5800X (65w eco profile)
Motherboard MSI B550 Gaming Plus
Cooling Scythe Mugen (rev 5)
Memory 2 x Kingston HyperX DDR4-3200 32 GiB
Video Card(s) AMD Radeon RX 7900 XT
Storage Samsung 980 Pro, Seagate Exos X20 TB 7200 RPM
Display(s) Nixeus NX-EDG274K (3840x2160@144 DP) + Samsung SyncMaster 906BW (1440x900@60 HDMI-DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay + USB 3.2 (A+C) 3.5" bay
Audio Device(s) Realtek ALC1150, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse Nixeus REVEL-X
Keyboard Tesoro Excalibur
Software Windows 10 Home 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
Yeah, and use a for-loop to copy the values into an array.
 
Joined
Dec 13, 2007
Messages
2,758 (0.43/day)
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:

Kreij

Senior Monkey Moderator
Joined
Feb 6, 2007
Messages
13,817 (2.08/day)
Location
Cheeseland (Wisconsin, USA)
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 ;)
 
Top