Post: C# - need help
08-10-2015, 03:08 PM #1
(adsbygoogle = window.adsbygoogle || []).push({}); im coding a tool in c# and i want it to display and the files in that folder. so i have made it but i want it to load on another form.
The listbox in form1 is empty. HELP

    
DirectoryInfo dinfo = new DirectoryInfo(pathCompile1337);
FileInfo[] Files = dinfo.GetFiles("*.gsc");
Form1 f2 = new Form1();
f2 = (Form1)Application.OpenForms["Form1"];
foreach (FileInfo file in Files)
{
listBoxControl2.Items.Add(file.Name);
f2.listBoxControl1.Items.Add(file.Name);
}
(adsbygoogle = window.adsbygoogle || []).push({});
08-10-2015, 05:21 PM #2
Chen Madhala
Pokemon Trainer
Originally posted by xMrMods View Post
im coding a tool in c# and i want it to display and the files in that folder. so i have made it but i want it to load on another form.
The listbox in form1 is empty. HELP

    
DirectoryInfo dinfo = new DirectoryInfo(pathCompile1337);
FileInfo[] Files = dinfo.GetFiles("*.gsc");
Form1 f2 = new Form1();
f2 = (Form1)Application.OpenForms["Form1"];
foreach (FileInfo file in Files)
{
listBoxControl2.Items.Add(file.Name);
f2.listBoxControl1.Items.Add(file.Name);
}


First
Instead of doing
    Form1 f2 = new Form1();
f2 = (Form1)Application.OpenForms["Form1"];

Just do
    Form1 f2 = (Form1)Application.OpenForms["Form1"];
Shorter
Next
Make sure that listBoxControl2 modifier is public
And make sure that the folder have .gsc files in, the code looks right to me.

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo