Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
the user should be able to select multiple values from CheckedListBox or ListBox and when the user click 'Save', the record should be inserted in a single column of a table.
I need code.
plz helppp
Posted

Is this what you are looking for?

I created a DataTable, added a single column and filled it with a for loop going through all the Selected Items of a ListBox.

C#
DataTable dt = new DataTable();
dt.Columns.Add("Column1");

for (int i = 0; i < listBox1.SelectedItems.Count; i++)
{
  dt.Rows.Add(listBox1.SelectedItems[i].ToString());
}

dataGridView.DataSource = dt;
 
Share this answer
 
You insert rows into a database table, not columns.

You can loop over the selected items in your (Checked)ListBox and insert a row for each item, setting the same column in each row. I don't know if that is what you want.

Nick
 
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