listboxes ...


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: listboxes ...

  1. #1
    bluezz Guest

    listboxes ...


    Hello

    I want to copy selected items in a listbox to another one by clicking a button.

    When the items are selected and the button click event fires, the items lose
    their selection state...

    I use this code:
    ------------------
    Private Sub btnLinks_Command(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.CommandEventArgs)
    Handles btnLinks.Command
    Dim i As Integer

    For i = 0 To lbTable.Items.Count - 1
    If lbTable.Items(i).Selected Then
    lbLinks.Items.Add(lbTable.Items(i))
    End If
    Next
    End Sub
    ------------------

    lbTable and lbLinks are listboxes ... when i trace the debugger trough the
    for loop, every item has it's selected prop "False" eventhough i selected
    multiple items on the page !

    I've probably took a wrong turn somewhere along the way to .NET :-)

    Thanks
    bluezz

  2. #2
    Constance J. Petersen Guest

    Re: listboxes ...

    Hi Bluezz,

    "bluezz" <bluezz_cool@hotmail.com> wrote in message
    news:3ca0a654$1@10.1.10.29...
    > I want to copy selected items in a listbox to another one by clicking a

    button.

    This code works for me:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles Button1.Click
    Dim li As ListItem
    For Each li In ListBox1.Items
    If li.Selected = True Then
    ListBox2.Items.Add(li.Value)
    End If
    Next
    End Sub

    --
    Constance Petersen, DevX newsgroup section leader
    SoftMedia Artisans, Inc.
    http://www.smartisans.com
    For useful, usable software and Web sites
    Featured Web design: http://www.keweenawnow.com/
    --
    Please reply in the newsgroup so everyone can benefit




  3. #3
    Ayhan Guest

    Re: listboxes ...


    Hi Bluezz,
    Be sure that the "EnableViewState" property of the page or of the list boxes
    is set to "true" value.

    Ayhan Kibar
    İşlemGIS (www.islem.com.tr)

    "Constance J. Petersen" <constance@smartisans.com> wrote:
    >Hi Bluezz,
    >
    >"bluezz" <bluezz_cool@hotmail.com> wrote in message
    >news:3ca0a654$1@10.1.10.29...
    >> I want to copy selected items in a listbox to another one by clicking

    a
    >button.
    >
    >This code works for me:
    >
    >Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
    >System.EventArgs) Handles Button1.Click
    > Dim li As ListItem
    > For Each li In ListBox1.Items
    > If li.Selected = True Then
    > ListBox2.Items.Add(li.Value)
    > End If
    > Next
    >End Sub
    >
    >--
    >Constance Petersen, DevX newsgroup section leader
    >SoftMedia Artisans, Inc.
    >http://www.smartisans.com
    >For useful, usable software and Web sites
    >Featured Web design: http://www.keweenawnow.com/
    >--
    >Please reply in the newsgroup so everyone can benefit
    >
    >
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center