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. Visual Basic
  4. selecting items in ListBox

selecting items in ListBox

Scheduled Pinned Locked Moved Visual Basic
helptutorial
3 Posts 2 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.
  • N Offline
    N Offline
    Nadroj
    wrote on last edited by
    #1

    i want to make a button on my form which will select all items in a listbox (and another button to deselect all). im not sure how to do this. also, i would like to do it with a for.. each loop, as im new to them.. not sure how to, in code, set the selecteditems (or whatever the property is, not sure which one to use).Dim item As String For Each item In ListBox1.Items ListBox1.SelectedItem = ListBox1.Items.IndexOf(item) Next
    is as far as iv got, but it doesnt seem to do anything.. any help appreciated ------------------------ Jordan. III

    J 1 Reply Last reply
    0
    • N Nadroj

      i want to make a button on my form which will select all items in a listbox (and another button to deselect all). im not sure how to do this. also, i would like to do it with a for.. each loop, as im new to them.. not sure how to, in code, set the selecteditems (or whatever the property is, not sure which one to use).Dim item As String For Each item In ListBox1.Items ListBox1.SelectedItem = ListBox1.Items.IndexOf(item) Next
      is as far as iv got, but it doesnt seem to do anything.. any help appreciated ------------------------ Jordan. III

      J Offline
      J Offline
      J4amieC
      wrote on last edited by
      #2

      First, ensure that your listbox's SelectionMode property is set to MultiSimple or MultiExtended. Next, ListBox has a method named SetSelected which is called with 2 arguments (index and boolean "Selected") So to select all items you could use this code: for(int i=0;i<ListBox1.Items.Count;i++) { ListBox1.SetSelected(i,true); }

      N 1 Reply Last reply
      0
      • J J4amieC

        First, ensure that your listbox's SelectionMode property is set to MultiSimple or MultiExtended. Next, ListBox has a method named SetSelected which is called with 2 arguments (index and boolean "Selected") So to select all items you could use this code: for(int i=0;i<ListBox1.Items.Count;i++) { ListBox1.SetSelected(i,true); }

        N Offline
        N Offline
        Nadroj
        wrote on last edited by
        #3

        :-D thanks alot! is there a way to do this with a for..each loop? using the collection of items in the listbox? thanks again ------------------------ Jordan. III

        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