Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. ListBox Controls

ListBox Controls

Scheduled Pinned Locked Moved C#
questiondatabase
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    Illegal Operation
    wrote on last edited by
    #1

    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

    D H 2 Replies Last reply
    0
    • I 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

      D Offline
      D Offline
      Dan Mos
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • I 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

        H Offline
        H Offline
        Henry Minute
        wrote on last edited by
        #3

        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.”

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups