Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
I finally got this worked out (I'm newbe to Windows Forms).
1. Create Form2 with checkedListBox, or you may already have it on another form. Add this code in Form2.cpp. The form designer doesn't like having loops in the *.h file so I had to put the code in *.cpp file.
#include "StdAfx.h"
#include "Form2.h"
using namespace System::IO;
namespace MyApplication { // Change this to the name of the application
void Form2::GetMyDrives()
{
array<DriveInfo^>^ allDrives = DriveInfo::GetDrives();
for each(DriveInfo^ d in allDrives)
{
this->checkedListBox1->Items->Add(d->Name);
}
}
};
2. Call the above function from the InitializeComponent() method in Form2.h, after other initialization for checkListBox1 component.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343