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. Windows Forms
  4. Browsing a ListBox

Browsing a ListBox

Scheduled Pinned Locked Moved Windows Forms
5 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.
  • B Offline
    B Offline
    benqazou
    wrote on last edited by
    #1

    Hey, I need to browse a multiselection ListBox, especially getting the Values of selected items. I filled it like this : lbox.DataSource = 'some datatable'; lbox.DisplayMember = "Col1"; lbox.ValueMember = "Col2"; The SelectionMode chose is : MultiSimple I need something like this foreach (item in the selected items) { Display its value.. etc } Thank you.

    L 1 Reply Last reply
    0
    • B benqazou

      Hey, I need to browse a multiselection ListBox, especially getting the Values of selected items. I filled it like this : lbox.DataSource = 'some datatable'; lbox.DisplayMember = "Col1"; lbox.ValueMember = "Col2"; The SelectionMode chose is : MultiSimple I need something like this foreach (item in the selected items) { Display its value.. etc } Thank you.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      a ListBox has a lot of useful properties, some related to the current selection; I would not be surprised if the documentation would show some with names starting with Selected. Would you care to read up on them? :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      Happy Holidays!


      B 1 Reply Last reply
      0
      • L Luc Pattyn

        a ListBox has a lot of useful properties, some related to the current selection; I would not be surprised if the documentation would show some with names starting with Selected. Would you care to read up on them? :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        Happy Holidays!


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

        Hey, Of course I've done many research before asking here.. The problem i have is not with getting the collection of selectediems (lbox.SelectedItems and lbox.SelectedIndices..etc) but when trying to retrieve the Value associated to a selecteditem.. Thanks.. for not helping..:-D

        L 1 Reply Last reply
        0
        • B benqazou

          Hey, Of course I've done many research before asking here.. The problem i have is not with getting the collection of selectediems (lbox.SelectedItems and lbox.SelectedIndices..etc) but when trying to retrieve the Value associated to a selecteditem.. Thanks.. for not helping..:-D

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          if the ListBox.DataSource is a DataTable, isn't each item in the ListBox a DataRow? :doh:

          Luc Pattyn [Forum Guidelines] [My Articles]


          Happy Holidays!


          B 1 Reply Last reply
          0
          • L Luc Pattyn

            if the ListBox.DataSource is a DataTable, isn't each item in the ListBox a DataRow? :doh:

            Luc Pattyn [Forum Guidelines] [My Articles]


            Happy Holidays!


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

            Thank you. I found some help here : http://www.eggheadcafe.com/articles/20051130b.asp[^] In fact here is the code : foreach (DataRowView drv in lbox.SelectedItems) { //Display column Id MessageBox.Show(drv.Row["Id"].ToString()); }

            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