Hello everyone,

Now this is my first time posting a question, if I do end up making it too general please let me know.

OK, now, I am in the process of programming a small program capable of accessing a sql database. That is no problem. Now, I have decided to look into the use of the combo box tool to avoid having different text boxes for the user to type in what he/she wishes to search for (for example, First name, last name, by nationality, etc) Now, the current method I am using is to set up an if condition (without entering into much detail, as it actually works, it checks if the option equals a certain index of the values entered, so if the selected index is 1, then it will execute the function associated with that index, such as search by name)

Now, the thing is, my classes are in French, and sadly the french forums I have found leave a lot to be desired (they always say search google, makes you wonder if they even read what is being posted), and documentation in french is well not much of a documentation at all.

Anyway, when I look at my code, well, it works, but I have the impression that there has to be a much less convoluted way to program a combo box. Do you have any suggestions of functions or methods I can look up? This is the first time I do such an assignment, and as such I think I am not doing a proper search due to lack of knowledge as to which keywords to search for.

Recommended Answers

All 4 Replies

Hi, OsheRono! Welcome at Daniweb.
Another way to do this (if I understand your post well) is to use a set of radiobuttons in a GroupBox control.

I think I get what you are talking about. :)
The best way I know to use a combo box is to bind it to an enumeration.

Bind Combo Box to Enum
That's a great link to get you started. Then when you want to retrieve the value and use it to decide what to do. Then you can use a switch statement. makes for ease of use.

Post back if you need more clarification. pretty simple but if the idea is too abstract I can create you an example project that shows what I mean.

Wow, thanks! That website link has a wealth of information, I found ways to streamline my code and to prevent user generated errors.

I'll be sure to pass it along to my classmates.

Thanks again!!

PS I think I got the idea, but since I have to use it with sql functions, I will do a little testing first. If I get stumped I'll let you know.

depending on how you connect to your database, you could build the query dynamically. For instance, use a struct to populate the combobox with DisplayMember set to a user friendly string and the ValueMember set to the matching column name (eg Display = "First Name", Value = "fName").
Then when you write your query use something like: "SELECT * FROM Customers WHERE " + combobox1.SelectedValue + " = '" + textbox1.Text + "'" .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.