✅ Creating a Search Bar for an app in Visual Studios
Hey, would it be possible for anyone to offer me some help with making a search bar for an app I am making? It is for a school project, and I am struggling to create the search bar. Any help at all would be greatly appreciated.
22 Replies
What's the project? Web? Desktop? Mobile?
What will you be searching? Files? Database?
It is a desktop app, and I am searching through a database, although I believe I already have tables with the contents that I want to search through.
Make a text field, then, and a button
On button press, take the contents of the field and query the database
I'll be honest, I am a little bit out of my depth on this project, do you think you could walk me through it on a VC while I share my screen?
SELECT p.Id, p.Title FROM Posts p WHERE p.Title LIKE %:query% LIMIT 10
The query would be something like that
Can't really join VC right now, sorryWhat does this part mean? %:query% LIMIT 10
That's ok, I will try my best to go off of your advice.
:query
would be the parameter to your query
%
is a placeholder meaning "anything"Meaning that anything can be passed through as a parameter?
So
%cat%
would match catastrophe, cat, copycat and vocationalOh that is exactly what I am looking for.
Thank you.
Well, in this case, the parameter should probably be a string
Yes.
How do I make a text field?
Currently, I have just been using data tables and datagridviews.
Depends on the UI framework you use
Winforms? WPF? Avalonia?
Which have all been snapped to the left
I think Winforms, it was a while ago when I first started the project, and I had a large break
I did consider Avalonia, but never did anything with it
Is there a way for me to check what I am using?
Take a look at the code for the main window
If it's a
Form
, it's Winforms
If it's a Window
it's WPFIt's Form
So Winforms
Yep
You should be able to just drag a text input and a button from the toolbox in the designer, then
And drop it wherever you need it to be
Anytime I drag anything into the designer it seems to mess my program up
Plus, it's tricky to scale with my datatable on the left side as that expands to fit the text inside of it
https://learn.microsoft.com/en-us/dotnet/desktop/winforms/controls/layout?view=netdesktop-8.0
You can use containers and stuff to make the layout how you want it
Ok great, thank you