Categories > Coding > C# >
[RQ] Need help to make a scripts [listbox] searchbox
Posted
So i've coded a listbox scripts searchbox.
But whenever i run the executor, it throws a error which says "Listbox Items Were Empty".
But Listbox had some scripts from the scripts folder!!!
Here Is The Code
private void SearchBar_TextChanged(object sender, TextChangedEventArgs e) { if (this.SearchBar.Text != "Search a Script") { this.listbox.Items.Clear(); foreach (FileInfo file in new DirectoryInfo(".\\Scripts").GetFiles()) { if (file.Name.ToLower().Contains(this.SearchBar.Text.ToLower())) { this.listbox.Items.Add(new ListBoxItem { Content = file.Name, Tag = file.FullName, Margin = new Thickness(0.0, 6.0, 0.0, 0.0) }); } } } }
Cancel
Post
VenomXD; Nick = Vini
Replied
I think you are idiot stupid because you literally clear the listbox so obviously there aren't gonna be any items
Cancel
Post
"Questionable intellegence, but I like the mystery" - CubeFaces
https://cdn.discordapp.com/attachments/1136067487847415848/1138948596679589898/sig.png
Replied
Make sure you add an if
statement with a log point to check for a "no files" exception. If it says there are no files, your code might be messed up with the wrong path or permissions or the code structure itself :)
Comments
Venom_XD -2 Reputation
Commented
I think the code is right. BUT BUT i have realized that it throws the error for the Instialize();.... And when it instializes there are no scripts in the listbox. but it reads the listbox code after reading the searchbar code. So when it reads, there are no items and after reading the listbox code, there are items
Lunox 29 Reputation
Commented
I'm not trying to be rude or anything but your English is making my head spin, Can you simplify your explanation a bit?
It seems like the code execution order is causing some shenanigans
Cancel
Post
A Quick One Before the Eternal Worm Devours Connecticut
Users viewing this thread:
( Members: 0, Guests: 1, Total: 1 )
Comments
Venom_XD -2 Reputation
Commented
If i don't clear it then it will spam making the same listbox items from scripts folder. and the error shows when i run the executor, not when i press searchbar
0
SeizureSalad 36 Reputation
Commented
Well if you clear it then there's nothing to search
0
Venom_XD -2 Reputation
Commented
@SeizureSalad
No, when write something in the scriptbar, it will make item with the item name in the searchbar. i mean guess i wrote P in the searchbar, then it will clear the items on the listbox and then make listbox items from the scripts folder which file names starts with P
0