ListBox Controls
-
Hi! I have a question. I have two ListBoxes with an Add and Remove Button. Currently I list all my options in ListBox1 using the following code:
ListBox1.DataSource = payItemClass.GetPayItems();
ListBox1.DisplayMember = "PayItem.Code";
ListBox1.ValueMember = "PayItem.Id";How can I move the items I select in ListBox1 to ListBox2 and then save them to my sql table? Thank you in Advance!!
Illegal Operation
-
Hi! I have a question. I have two ListBoxes with an Add and Remove Button. Currently I list all my options in ListBox1 using the following code:
ListBox1.DataSource = payItemClass.GetPayItems();
ListBox1.DisplayMember = "PayItem.Code";
ListBox1.ValueMember = "PayItem.Id";How can I move the items I select in ListBox1 to ListBox2 and then save them to my sql table? Thank you in Advance!!
Illegal Operation
ListBox has a property named SelectedItems. Use it to get the selected itmes in listbox1 and add them to listbox2. As for adding them to SQL either use stored procs or querys but try to use parameters. Something like this silly example to copy the items from one lst to another:
listBox2.BeginUpdate(); listBox2.Items.Clear(); foreach (var item in listBox1.SelectedItems) { listBox2.Items.Add(item); } listBox2.EndUpdate();
pseudo only kind of(for SQL table):
SQLConnection con = new SqlCommand(ConnStringHere);
SQLCommand cmd = new SqlCommand();
cmd.Conection = con;
cmd.CommandText = "Inserto Into TblName(ColName1, ColName2) Values(@paramName1, @paramName2)"cmd.Parameters.AddWithValue("@paramName", paramValue);
//add all the params needed
.
.
.//open the con and execute the command
Just an irritated, ranting son of ... an IT guy. At your trolling services
modified on Wednesday, May 5, 2010 2:50 AM
-
Hi! I have a question. I have two ListBoxes with an Add and Remove Button. Currently I list all my options in ListBox1 using the following code:
ListBox1.DataSource = payItemClass.GetPayItems();
ListBox1.DisplayMember = "PayItem.Code";
ListBox1.ValueMember = "PayItem.Id";How can I move the items I select in ListBox1 to ListBox2 and then save them to my sql table? Thank you in Advance!!
Illegal Operation
If you have not yet solved your problem, try looking at this thread[^]. The problem sounds basically the same as yours.
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”