Jump to content
Sign in to follow this  
Lainkes

Saving multiple listbox items to db

Recommended Posts

Hello,

 

On my form (Person) , I have a Listbox component that I fill with values from another table. I activated the multiselect option.

How can I now save the selected records in my database, linked to the Person.

 

When I open the Person form again, the selected records needs to be selected.

 

Thanks 

 

Lainkes

 

Share this post


Link to post

I found a component that is called TCheckListBox.

I can fill this with values from my database. So that's works fine.

Now I need to know how to save the selected data to my database, linked to the key of  my Person table.

Share this post


Link to post

I already managed to fill the Checkboxlist with items from my table.
But now I'm wondering how I can write the selected items to a table and retrieve them when a person form is opened.

 

Thanks

Share this post


Link to post

You iterate over the items, check if it's checked if it is, save it to your table

 

for var i := 0 to (FileListBox1.Items.Count - 1) do begin
  if FileListBox1.Selected[i] then
    begin
      // save item to table FileListBox1.Items[i] 
    end;

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×