3

I'm in a Vb.Net application coding and really a newbie here, I just finished creating my first MySQL connexion to a remote server ..

Anyway, What I'm asking about here is how to gather data from a table and load it into a CheckBoxList, so that user can have a list of items from the table, and he checks the ones he need, that I will later.

Thank you all the community here :)

3
  • What platform? Winforms, WPF, Silverlight, ASPX, other? Are you familiar with sql statements? Commented Jun 30, 2013 at 3:16
  • Winforms, VB.net 2010, and yes I am. Commented Jun 30, 2013 at 22:29
  • Thanks youfor asking a basic level question. At times people forget that we are not all experts and some basic help is needed. I had the same question and was frustrated with the hyper advanced answers. Commented Jan 13, 2022 at 19:15

1 Answer 1

1

You first need to get the data that you need into a table. Then loop through that table and add it to your CheckedListBox.

Here's a short example:

 Dim dtPersons As DataTable
 dtPersons = GetPersons()

 For Each dRow As DataRow In dtPersons.Rows
   CheckedListBox1.Items.Add(dRow.Item("LastName"))
 Next

This will loop through a datatable and add an item to the checkedlistbox each time with last name.

GoodLuck!

Sign up to request clarification or add additional context in comments.

5 Comments

The function GetPersons is .. ?
That was added to get you started; this function would pull your data in. It can be whatever you want it to be; you already make a connection from what you state. So all you need to do is perform a query to get what you need in a function that returns a data table.
Is there any ability to load values for each item ? (Value, Item)
No it's either checked or not; the checked listbox items are already what you want because you are already displaying them. For example: red apples and green apples are per say in your listbox. You only want the red apples so you just check them. Well know you have your item "red apples".
You can also loop through the checked listbox for example: For Each i As Object In CheckedListBox1.CheckedItems TextBox1.Text += i.ToString() Next

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.