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 value from listbox items

Get value from listbox items

Scheduled Pinned Locked Moved C#
question
4 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, i am using to retrive the value from listbox items as

    foreach (var obj in listbox.Items)
    {
    ?????????????????
    }

    but i have no idea what should be in foreach body. thanks

    RaviBeeR D J 3 Replies Last reply
    0
    • Z zeeShan anSari

      hi, i am using to retrive the value from listbox items as

      foreach (var obj in listbox.Items)
      {
      ?????????????????
      }

      but i have no idea what should be in foreach body. thanks

      RaviBeeR Offline
      RaviBeeR Offline
      RaviBee
      wrote on last edited by
      #2

      It depends what you want to do with the item. Unlike a ListViewItem, a list box item is just an object, whose ToString() method is called to render its text in the list box. /ravi

      My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

      1 Reply Last reply
      0
      • Z zeeShan anSari

        hi, i am using to retrive the value from listbox items as

        foreach (var obj in listbox.Items)
        {
        ?????????????????
        }

        but i have no idea what should be in foreach body. thanks

        D Offline
        D Offline
        dug_r
        wrote on last edited by
        #3

        zeeShan, I hope this helps. It depends on what you want to do with your items. They are usually cast at some point. Consider this code. When something is selected in listBox1, it copies all of the contents into listBox2: private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { foreach (string item in listBox1.Items) { listBox2.Items.Add(item); } }

        1 Reply Last reply
        0
        • Z zeeShan anSari

          hi, i am using to retrive the value from listbox items as

          foreach (var obj in listbox.Items)
          {
          ?????????????????
          }

          but i have no idea what should be in foreach body. thanks

          J Offline
          J Offline
          Jabbar_espania
          wrote on last edited by
          #4

          Here i provide you source code wish that help you : for example if you want to calculate all values of liste item . Dim sum As Integer For Each item As String In data.ListBox1.Items sum += Double.Parse(item) Next textbox1.text = sum It will show total value of Items

          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