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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. getting the selectedItem in a checkedListBox from another method

getting the selectedItem in a checkedListBox from another method

Scheduled Pinned Locked Moved C#
helpquestion
5 Posts 4 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.
  • T Offline
    T Offline
    Twyce
    wrote on last edited by
    #1

    I am trying to access checked Items in a checkedListbox from another method.Problem is, using "Selecteditem" and "SelectedIndex" does not work, it appears as if there aren't any items selected from the list. is there any other way I can read from the CheckedBoxList list or What am i doing wrong? Please help

    H D S 3 Replies Last reply
    0
    • T Twyce

      I am trying to access checked Items in a checkedListbox from another method.Problem is, using "Selecteditem" and "SelectedIndex" does not work, it appears as if there aren't any items selected from the list. is there any other way I can read from the CheckedBoxList list or What am i doing wrong? Please help

      H Offline
      H Offline
      Henry Minute
      wrote on last edited by
      #2

      Without seeing your code it is not easy to offer any suggestion. Normally just using myCheckedListBox.SelectedIndex should work. Please post the code where you are trying to do it, so that people can try to help you.

      Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

      1 Reply Last reply
      0
      • T Twyce

        I am trying to access checked Items in a checkedListbox from another method.Problem is, using "Selecteditem" and "SelectedIndex" does not work, it appears as if there aren't any items selected from the list. is there any other way I can read from the CheckedBoxList list or What am i doing wrong? Please help

        D Offline
        D Offline
        DaveyM69
        wrote on last edited by
        #3

        Is this WinForms? If so, are you getting confused between SelectedItems and CheckedItems?

        CheckedListBox.CheckedItemCollection checkedItems = checkedListBox.CheckedItems;

        Dave
        BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
        Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
        Why are you using VB6? Do you hate yourself? (Christian Graus)

        H 1 Reply Last reply
        0
        • D DaveyM69

          Is this WinForms? If so, are you getting confused between SelectedItems and CheckedItems?

          CheckedListBox.CheckedItemCollection checkedItems = checkedListBox.CheckedItems;

          Dave
          BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
          Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
          Why are you using VB6? Do you hate yourself? (Christian Graus)

          H Offline
          H Offline
          Henry Minute
          wrote on last edited by
          #4

          Good spot!!

          Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

          1 Reply Last reply
          0
          • T Twyce

            I am trying to access checked Items in a checkedListbox from another method.Problem is, using "Selecteditem" and "SelectedIndex" does not work, it appears as if there aren't any items selected from the list. is there any other way I can read from the CheckedBoxList list or What am i doing wrong? Please help

            S Offline
            S Offline
            Swetha Srinivasan
            wrote on last edited by
            #5

            Lets name the checklistbox as table list.whenever an item is checked or unchecked just add them to a data table(_selectedTables). private void tableList_ItemCheck(object sender, ItemCheckEventArgs e) { string names = tableList.GetItemText(tableList.Items[e.Index]); CheckState currentState=e.NewValue; if (currentState.ToString() == "Checked") { DataRow newRow = _selectedTables.NewRow(); _selectedTables.Rows.Add(newRow); newRow["Table"] = names; } else { DataRow[] dr = _selectedTables.Select("Table = '" + names + "'"); if (dr.Length > 0) _selectedTables.Rows.Remove(dr[0]); } } And then use this method to retrieve the selection public DataTable ReturnSelectedTables { get { return _selectedTables; } } Hope this helps you.

            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