Categories > Coding > C# >

[RQ] Need help to make a scripts [listbox] searchbox

Posts: 47

Threads: 16

Joined: Apr, 2023

Reputation: -2

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)
				});
			}
		}
	}
}
  • 0

VenomXD; Nick = Vini

SeizureSalad

i love femboys

Posts: 1153

Threads: 79

Joined: Mar, 2021

Reputation: 36

Replied

I think you are idiot stupid because you literally clear the listbox so obviously there aren't gonna be any items

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

  • 0

"Questionable intellegence, but I like the mystery" - CubeFaces

https://cdn.discordapp.com/attachments/1136067487847415848/1138948596679589898/sig.png

Lunox

Mole

vip

Posts: 58

Threads: 6

Joined: Jun, 2022

Reputation: 29

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

  • 0

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

 

  • 0

Venom_XD -2 Reputation

Commented

@Lunox

I'm from Argentina. I can't speak English that much like Messi

  • 0

  • 0

A Quick One Before the Eternal Worm Devours Connecticut

Users viewing this thread:

( Members: 0, Guests: 2, Total: 2 )