Retrieving data from database into a checkedlistbox

SkilledDreamer

New member
Joined
Jul 17, 2014
Messages
2
Programming Experience
Beginner
Hey forum!

I am using VS 2012 and Sequel Server Compact 4.0 database. I am trying to retrieve data from a table within the database to populate into a checkedlistbox through my windows form as soon as it gets opened up. I have the database code to retrieve the information within a different class while my checkedlistbox is in a seperate class. I was trying to use OOP and populate data into the checkedlistbox, but I'm not sure how to code this. I tried using (this being an example) checkedlistbox.Items.Add(databaseObject.Method(items)); but that didn't work. What should I do here?

SkilledDreamer
 
I am using VS 2012 and Sequel Server Compact 4.0 database.

It's not "Sequel". It's pronounced that way but it's written "SQL". It's an acronym that stands for Structured Query Language. People say "sequel" because it's easier and people might think you're Spanish if you say "es que el". ;)

As for the issue, that Add method simply adds one item to the CheckedListBox. If you want to add multiple items then you need to use AddRange.

That said, I would tend to bind the data, which means assigning the list to the DataSource property. Juts note that binding won't recognise the check boxes in the control, so you still have to determine which items are checked and unchecked manually.
 
It's not "Sequel". It's pronounced that way but it's written "SQL". It's an acronym that stands for Structured Query Language. People say "sequel" because it's easier and people might think you're Spanish if you say "es que el". ;)

As for the issue, that Add method simply adds one item to the CheckedListBox. If you want to add multiple items then you need to use AddRange.

That said, I would tend to bind the data, which means assigning the list to the DataSource property. Juts note that binding won't recognise the check boxes in the control, so you still have to determine which items are checked and unchecked manually.

Ooops, you're right about SQL and not Sequel. My mistake. Okay, so I can have the checkedlistbox.AddRange happen, but what about retrieving information from my database? Should I have it call that method through the database object on the line underneath of it? I mostly just need numbers to be sent over. I want to have numerical values (which I'll put them into double variables) sent over. Unless I can have my database class put information into my checkedlistbox from form 2 through it, I don't have a single clue on how to make this happen. Any suggestions?
 
but what about retrieving information from my database? Should I have it call that method through the database object on the line underneath of it? I mostly just need numbers to be sent over. I want to have numerical values (which I'll put them into double variables) sent over. Unless I can have my database class put information into my checkedlistbox from form 2 through it, I don't have a single clue on how to make this happen. Any suggestions?
I'm afraid that that's all a bit vague. The form creates an instance of the data access class, calls the method that returns the list and then uses the list. If you want more than that then you'll need to be much clearer and specific.
 
Back
Top Bottom