Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone.....am new to .net and i need some help from you all..how can i populate the listbox with data from another table and after selecting more than one item in listbox..i want to save the selected items into the database.if we select more than one items from listbox it should be stored in the database seperated by commas..
thanx
Posted

The basic answer to this question is, write some code. If you have no idea how to start, I don't really know how to answer you, and expect you to understand the answer. You can populate a listbox row by row, or from a data source. You can iterate over your selected items and do whatever you want with them. Really, you need to read a basic book or something and attempt this and ask specific questions, as it stands, the answers have to be vague, as the question is vague, and the answers are so straightforward as to leave us wondering why you've not bothered to read the help, do some research, etc, and why you're attempting a task that's both straightforward, and yet you have no idea how to do it ?
 
Share this answer
 
It's not that difficult. Here's my concept:

1. Declaration of ListBox.
<ListBox SelectionMode="Multiple" x:Name="xList"/>

The important thing is setting SelectionMode.

2. Then creating and saving the string on ButtonClick. Nothing sophisticated here just:
string s="";
foreach(System.Windows.Controls.ListBoxItem li in xList.SelectedItems)
{
   s+= (li.Content as (whatever object youre binding here)).(Field you need to save);
   s+=";";
}
SaveToDB(s);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900