Error adding list in "Checked List Box"

Asked

Viewed 28 times

-2

Adding the name of some files in a folder to a "Checked List Box" does not show anything in the List Box.

        ListBox mylist = new ListBox();

        DirectoryInfo d = new DirectoryInfo(@"C:\Program Files (x86)\Nmap\scripts");
        FileInfo[] Files = d.GetFiles("*.nse"); 
        string str = "";
        foreach (FileInfo file in Files)
        {
            mylist.Items.Add(file);
        } 
        checkedListBox1.Items.Add(mylist);

I am using this code when run appears like this:

  • is doing exactly what it should, because Fileinfo is an object, a class. If you are expecting information from the archive, such as its name, please read the documentation to better understand: https://docs.microsoft.com/en-us/dotnet/api/system.io.fileinfo?view=netframework-4.8 maybe what you want is to mylist.Items.Add(file.Name)

1 answer

0


try to foreach on checkedlist as well

   foreach (var item in mylist)
   {
       checkedListBox1.Items.Add(item);
   } 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.