list box checked names

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hrvoje Voda

    list box checked names

    I got the index of all checked values, but I don't know how to read data of
    that value?

    For example.. in list box I have Names of users. First is John(index 1),
    Second is Jack(index 2) and so on...
    How to get the names ?

    Hrcko


  • Salvador

    #2
    RE: list box checked names

    Hi,

    If you have all the indexes you can use the following statements:

    YourList.Items[index].Text --> First column
    YourList.Items[index].SubItems[columnIndex].Text --> other columns

    Hope this helps
    SAlva

    Cheers
    Salva



    "Hrvoje Voda" wrote:
    [color=blue]
    > I got the index of all checked values, but I don't know how to read data of
    > that value?
    >
    > For example.. in list box I have Names of users. First is John(index 1),
    > Second is Jack(index 2) and so on...
    > How to get the names ?
    >
    > Hrcko
    >
    >
    >[/color]

    Comment

    • James Curran

      #3
      Re: list box checked names

      FIrst of all, when talking about a control, it's vitally important that
      you say if you are using a WinForms control (for Windows apps), or a
      WebControl (for ASP.NET apps). They are quite different, but they often
      have the same names.

      So, I'm going to assume that you are using a WinForms CheckedListBox
      control, and that you've gotten the list of indexes via
      checkedListBox. CheckedIndices property. Well, the simpliest thing is to
      ignore that and use checkedListBox. CheckedItems which gives you exactly what
      you want.

      If you really want to continue using checkedListBox. CheckedIndices, you
      can access the items via the Items property:

      foreach( int i in checkedListBox. CheckedIndices)
      {
      string name = checkedListBox. Items[i] as string;
      }

      "Hrvoje Voda" <hrvoje.voda@lu atech.com> wrote in message
      news:d3gl73$rgr $1@ss405.t-com.hr...[color=blue]
      > I got the index of all checked values, but I don't know how to read data[/color]
      of[color=blue]
      > that value?
      >
      > For example.. in list box I have Names of users. First is John(index 1),
      > Second is Jack(index 2) and so on...
      > How to get the names ?[/color]


      Comment

      • Hrvoje Voda

        #4
        Re: list box checked names

        I don't have Text after items.
        I'm using checked ListBox.


        "Salvador" <Salvador@discu ssions.microsof t.com> wrote in message
        news:0F7EF184-1C2C-4C8A-99FF-7685EF99CEEA@mi crosoft.com...[color=blue]
        > Hi,
        >
        > If you have all the indexes you can use the following statements:
        >
        > YourList.Items[index].Text --> First column
        > YourList.Items[index].SubItems[columnIndex].Text --> other columns
        >
        > Hope this helps
        > SAlva
        >
        > Cheers
        > Salva
        >
        >
        >
        > "Hrvoje Voda" wrote:
        >[color=green]
        >> I got the index of all checked values, but I don't know how to read data
        >> of
        >> that value?
        >>
        >> For example.. in list box I have Names of users. First is John(index 1),
        >> Second is Jack(index 2) and so on...
        >> How to get the names ?
        >>
        >> Hrcko
        >>
        >>
        >>[/color][/color]


        Comment

        • Morten Wennevik

          #5
          Re: list box checked names

          The CheckedItemColl ection stores objects so you need to cast each item to
          its original type, which in your case appears to be System.String

          foreach(int i in checkedListBox1 .CheckedIndices )
          {
          string s = (string)checked ListBox1.Items[i];
          // do something with s
          }

          --
          Happy Coding!
          Morten Wennevik [C# MVP]

          Comment

          • Hrvoje Voda

            #6
            Re: list box checked names

            This doesn't work.

            As a result I get : System.Windows. Forms.ListBox+S electedObjectCo llect

            But, when I put items in listBoxCollecti on (in properties) then I get a
            result.

            Is it a problem because I'm using dataset?


            "James Curran" <jamescurran@mv ps.org> wrote in message
            news:%231uBx42P FHA.2132@TK2MSF TNGP14.phx.gbl. ..[color=blue]
            > FIrst of all, when talking about a control, it's vitally important that
            > you say if you are using a WinForms control (for Windows apps), or a
            > WebControl (for ASP.NET apps). They are quite different, but they often
            > have the same names.
            >
            > So, I'm going to assume that you are using a WinForms CheckedListBox
            > control, and that you've gotten the list of indexes via
            > checkedListBox. CheckedIndices property. Well, the simpliest thing is to
            > ignore that and use checkedListBox. CheckedItems which gives you exactly
            > what
            > you want.
            >
            > If you really want to continue using checkedListBox. CheckedIndices, you
            > can access the items via the Items property:
            >
            > foreach( int i in checkedListBox. CheckedIndices)
            > {
            > string name = checkedListBox. Items[i] as string;
            > }
            >
            > "Hrvoje Voda" <hrvoje.voda@lu atech.com> wrote in message
            > news:d3gl73$rgr $1@ss405.t-com.hr...[color=green]
            >> I got the index of all checked values, but I don't know how to read data[/color]
            > of[color=green]
            >> that value?
            >>
            >> For example.. in list box I have Names of users. First is John(index 1),
            >> Second is Jack(index 2) and so on...
            >> How to get the names ?[/color]
            >
            >[/color]


            Comment

            Working...