Listbox collection

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Anand Ganesh

    #1

    Listbox collection

    Hello All,

    I want to go through each item in a Listbox collection. How will I do this?

    I was looking for ListBoxItem but nothing is available?

    Any suggestions please?

    Thanks
    Anand Ganesh


  • zacks@construction-imaging.com

    #2
    Re: Listbox collection

    On Aug 20, 2:57 pm, "Anand Ganesh" <agan...@nobe l-systems.comwrot e:
    Hello All,
    >
    I want to go through each item in a Listbox collection. How will I do this?
    >
    I was looking for ListBoxItem but nothing is available?
    >
    Any suggestions please?
    >
    Thanks
    Anand Ganesh
    It's ListBox.Items.

    Comment

    • Nicholas Paldino [.NET/C# MVP]

      #3
      Re: Listbox collection

      Anand,

      The listbox exposes the Items property, which returns a type of
      ListBox.ObjectC ollection. This type implements IEnumerable, which means you
      can use in a for each statement.

      The ListBox.ObjectC ollection class holds instances of type object
      though. The ListBox accesses the property indicated in the DisplayMember
      property of the ListBox, or calls ToString on the object, if the
      DisplayMember property does not have a value.

      Also, if the list box is data-bound, then the Items property will have
      no items in it, and you will have to access the listbox's data source
      directly.


      --
      - Nicholas Paldino [.NET/C# MVP]
      - mvp@spam.guard. caspershouse.co m

      "Anand Ganesh" <aganesh@nobe l-systems.comwrot e in message
      news:OQfQvr14HH A.2108@TK2MSFTN GP02.phx.gbl...
      Hello All,
      >
      I want to go through each item in a Listbox collection. How will I do
      this?
      >
      I was looking for ListBoxItem but nothing is available?
      >
      Any suggestions please?
      >
      Thanks
      Anand Ganesh
      >

      Comment

      • SurferJoe

        #4
        Re: Listbox collection

        private void button1_Click(o bject sender, EventArgs e)
        {
        string s = "";
        for (int i = 1; i <= lvwMyListView.I tems.Count - 1; i++)
        {
        s = s + lvwMyListView.I tems[i].Text + char.Parse("\n" );
        }
        MessageBox.Show ( s);

        }


        Comment

        • Anand Ganesh

          #5
          Re: Listbox collection

          Hello All,

          Thank you very much for the quick reply and clarification.

          Regards
          Anand


          "Anand Ganesh" <aganesh@nobe l-systems.comwrot e in message
          news:OQfQvr14HH A.2108@TK2MSFTN GP02.phx.gbl...
          Hello All,
          >
          I want to go through each item in a Listbox collection. How will I do
          this?
          >
          I was looking for ListBoxItem but nothing is available?
          >
          Any suggestions please?
          >
          Thanks
          Anand Ganesh
          >

          Comment

          Working...