I am not a programmer, nor do I pretend to be. I have slowly been taking in advice from videos I have been looking at through youtube to help with my advancement of knowledge in C#. I was looking for a way to combine a list box item to a database. the function would be to click on the item name and bring up a database that is associated with it. if anyone would be able to help me out with that much would be appreciated.

Edited 2 Years Ago by Reverend Jim: wrong forum

This can be done rather easily. First of all let me ask, do you know how to build forms? Next do you know about events?

What you'll want is an event for the ListBox, the click one (or index change ... can't remember if that ones exists for ListBox). On the firing of that event, you'll want to get the value that is selected (there is a property tied to the ListBox, something like "GetSelectedValue" or something like that), use that value to query your database, fetching results, which you can use for display sake.

That's a quick break down. I would advise you start to build something yourself, do as much as you can, then come back to us. This helps us see where exactly you are at, what you know, and how we can help

Edited 2 Years Ago by JOSheaIV

I have set this application to a windows form, this is just an assumption, but if you click on the item such as a button, textbox...etc it upons up an even to that specific item? what I am trying to accomplish is different items in the list will be associated with different databases. when you click on the item it will bring up that particular database.

On a side note, I am trying to get each item in the list to display the number of records associated with it. the list box would look something like this:

houses (3000)
garages (345)
driveways (376)

as you can see the number of rows associated with each database will be displayed to the side of the item as the record count.

Ah yes. All this is easily possible, the count works well with SQL, as there is a function called "COUNT()"

Again, my advice, try to build something, do anything you can, it allows for us to get a starting point on where to help you.

Hi, for this pupose you need to first create a database and table(s) of course. Correct me if I am wrong, I think you need to refer to a particular table data to a listbox item on selection and for that you need to create a click event on that particular listbox item.
I will surely post the code related to the same but first could you please confirm on this that is this you intend to do ?

Do you know SQL? If you do, the C# part of it is rather easy...

So for starters, write down a SQL statement that gets all of the information that you want, then we will help you incorporate that into a C# app, and later, when you are comfortable with that, we will show you how to rather have your SQL statement in a stored proc and why it might be better to do it that way.

This article has been dead for over six months. Start a new discussion instead.