c# - Winform Listbox Select Items from Database -


this question has answer here:

i have 3 database tables:

  • a list of cars,
  • a list of people, ,
  • the third many-to-many table of people cars.

on winform person, have listbox of available cars. loading listbox database easy (databinding). there easy way select cars person has based on many many table or have resort looping through listbox , comparing many many table?

so, if have john doe , owns ford , honda, , choices in lsitbox chevy, honda, ford, toyota , nissan, honda , ford should selected when john doe's form opened.

thanks help!

edit according author's comment:

alright got wrong @ first. guess there no real "best practice", have loop through listbox either way.

something like:

// assuming dtpersonscars datatable containing 2 primary keys, persons , cars        lstboxcars.selectionmode = system.windows.forms.selectionmode.multisimple;        (int = 0; < lstboxcars.items.count; i++)        {           if (dtpersonscars.rows.find(new object[]{"person", lstboxaenderungen.items[i].tostring()}) != null)               lstboxcars.setselected(i, true);        } 

Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -