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. Get values from ListBox

Get values from ListBox

Scheduled Pinned Locked Moved C#
questionhelp
5 Posts 4 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.
  • Z Offline
    Z Offline
    zeeShan anSari
    wrote on last edited by
    #1

    hi all, :) I have ListBox where are 10 items. i set ListBox.DisplayMember = "FirstName"; ListBox.ValueMember = "EmployeeID"; then ListBox shows the Employee's FirstName.My problem is that how do i get the all EmployeeID from ListBox? :(

    W H 2 Replies Last reply
    0
    • Z zeeShan anSari

      hi all, :) I have ListBox where are 10 items. i set ListBox.DisplayMember = "FirstName"; ListBox.ValueMember = "EmployeeID"; then ListBox shows the Employee's FirstName.My problem is that how do i get the all EmployeeID from ListBox? :(

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      ListControl.SelectedValue Property [^] will return the value for selected item.

      The need to optimize rises from a bad design. My articles[^]

      1 Reply Last reply
      0
      • Z zeeShan anSari

        hi all, :) I have ListBox where are 10 items. i set ListBox.DisplayMember = "FirstName"; ListBox.ValueMember = "EmployeeID"; then ListBox shows the Employee's FirstName.My problem is that how do i get the all EmployeeID from ListBox? :(

        H Offline
        H Offline
        Hossein Afyuoni
        wrote on last edited by
        #3

        Hi ... I think it's good for you:

           List val = new List();         
           for (int i = 0; i < listBox1.Items.Count; i++)
           {
               lst.SelectedIndex = i;
               val.Add((Int32)lst.SelectedValue);
           }
        

        In val you have All EmployeeIDs ... But this code is not logical code X| ...

        if(Human.live)
        {
        Human.peaceful = false;
        while(true)
        {
        Human.love(Human girl, Human Boy);
        }
        }

        Z 1 Reply Last reply
        0
        • H Hossein Afyuoni

          Hi ... I think it's good for you:

             List val = new List();         
             for (int i = 0; i < listBox1.Items.Count; i++)
             {
                 lst.SelectedIndex = i;
                 val.Add((Int32)lst.SelectedValue);
             }
          

          In val you have All EmployeeIDs ... But this code is not logical code X| ...

          if(Human.live)
          {
          Human.peaceful = false;
          while(true)
          {
          Human.love(Human girl, Human Boy);
          }
          }

          Z Offline
          Z Offline
          zeeShan anSari
          wrote on last edited by
          #4

          i found ArrayList objList = new ArrayList(); foreach (DataRowView obj in listBox1.Items) { objList.Add(obj[0]); } :-D :-D :-D

          G 1 Reply Last reply
          0
          • Z zeeShan anSari

            i found ArrayList objList = new ArrayList(); foreach (DataRowView obj in listBox1.Items) { objList.Add(obj[0]); } :-D :-D :-D

            G Offline
            G Offline
            Guffa
            wrote on last edited by
            #5

            You should rather use a generic list (The ArrayList class is practically deprecated): List<object> objList = new List<object>(listBox1.Items); or just get a reference to the Items collection: ListBox.ObjectCollection objList = listBox1.Items;

            Despite everything, the person most likely to be fooling you next is yourself.

            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