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. Retrieve Listbox items

Retrieve Listbox items

Scheduled Pinned Locked Moved C#
questioncsharp
5 Posts 3 Posters 1 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.
  • B Offline
    B Offline
    BillAnton
    wrote on last edited by
    #1

    Hello, Using C# on a web form with a textbox for the user to enter a word and then click on a button to have the word entered into a listbox. After the user has entered as many words as they wish they can then click on another button to have all of the words in the listbox processed. My question is: how do I retreive the words from the listbox? I would think I could loop through the listbox and get each word but I am not finding anything like this in my searches. For (int i = 0; i < Listbox1.Count; i = i+1) { wordlist[i] = Listbox1.?????; //processing code here } Can someone aim me in the right direction? Regards, Bill Antonacchio

    J 1 Reply Last reply
    0
    • B BillAnton

      Hello, Using C# on a web form with a textbox for the user to enter a word and then click on a button to have the word entered into a listbox. After the user has entered as many words as they wish they can then click on another button to have all of the words in the listbox processed. My question is: how do I retreive the words from the listbox? I would think I could loop through the listbox and get each word but I am not finding anything like this in my searches. For (int i = 0; i < Listbox1.Count; i = i+1) { wordlist[i] = Listbox1.?????; //processing code here } Can someone aim me in the right direction? Regards, Bill Antonacchio

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      for(int i=0; i<listBox1.Items.Count; i++)
      {
      wordlist[i] = listBox1.Items[i];
      // processing code here
      }

      #include "witty_sig.h"

      B 1 Reply Last reply
      0
      • J Judah Gabriel Himango

        for(int i=0; i<listBox1.Items.Count; i++)
        {
        wordlist[i] = listBox1.Items[i];
        // processing code here
        }

        #include "witty_sig.h"

        B Offline
        B Offline
        BillAnton
        wrote on last edited by
        #3

        Thank you, I guess. When I try to use this code there are several things that come up in the Build Error list in VS.NET. Doesn't there need to be a condition and an iteratr in the For statement. Also, Property or indexer 'string.this[int]' cannot be assigned to -- it is read only AND Cannot implicitly convert type 'System.Web.UI.WebControls.ListItem' to 'char' appear in the Build Error list. Can you give me a little more detail? This help is very much appreciated.

        N 1 Reply Last reply
        0
        • B BillAnton

          Thank you, I guess. When I try to use this code there are several things that come up in the Build Error list in VS.NET. Doesn't there need to be a condition and an iteratr in the For statement. Also, Property or indexer 'string.this[int]' cannot be assigned to -- it is read only AND Cannot implicitly convert type 'System.Web.UI.WebControls.ListItem' to 'char' appear in the Build Error list. Can you give me a little more detail? This help is very much appreciated.

          N Offline
          N Offline
          netclectic
          wrote on last edited by
          #4

          I think you want ListBox1.Items[i].Text

          B 1 Reply Last reply
          0
          • N netclectic

            I think you want ListBox1.Items[i].Text

            B Offline
            B Offline
            BillAnton
            wrote on last edited by
            #5

            Thank you tried it and that works! Bill

            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