Advertisement
NeonFox__

ListBox2

Jun 1st, 2020 (edited)
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. -- put into listbox
  2.  
  3. private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
  4. {
  5. if (listBox1.SelectedItem == null)
  6. {
  7. MessageBox.Show("Please select a tab in the listbox.", "Error.", MessageBoxButtons.OK, MessageBoxIcon.Information);
  8. return;
  9. }
  10. textBox1.Text = File.ReadAllText($"./Scripts/{listBox1.SelectedItem}");
  11. }
  12.  
  13. -- refresh code
  14.  
  15. listBox1.Items.Clear();//Clear Items in the ListBox
  16. Functions.PopulateListBox(listBox1, "./Scripts", "*.txt");
  17. Functions.PopulateListBox(listBox1, "./Scripts", "*.lua");
  18.  
  19.  
  20. -- put into functions
  21.  
  22. public static void PopulateListBox(ListBox lsb, string Folder, string FileType)
  23. {
  24. DirectoryInfo dinfo = new DirectoryInfo(Folder);
  25. FileInfo[] Files = dinfo.GetFiles(FileType);
  26. foreach (FileInfo file in Files)
  27. {
  28. lsb.Items.Add(file.Name);
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement