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. C#
  4. deleting items from listbox with DEL

deleting items from listbox with DEL

Scheduled Pinned Locked Moved C#
question
2 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.
  • M Offline
    M Offline
    mizitras
    wrote on last edited by
    #1

    I've programmed a button, called 'Remove' to delete items, by counting the amount of selections, and than by a for-loop, doing listbox.remove, and when the loop is done, all selected items were deleted. But it just doesn't seem so userfriendly with this button. Does listbox have something simple that allows the delete-key the do the same as the remove-method? Or should I be thinking in terms of making an event for listbox, and check if the 'DEL'-key was pressed, and then execute the same code as with my button? Thanks in advance

    L 1 Reply Last reply
    0
    • M mizitras

      I've programmed a button, called 'Remove' to delete items, by counting the amount of selections, and than by a for-loop, doing listbox.remove, and when the loop is done, all selected items were deleted. But it just doesn't seem so userfriendly with this button. Does listbox have something simple that allows the delete-key the do the same as the remove-method? Or should I be thinking in terms of making an event for listbox, and check if the 'DEL'-key was pressed, and then execute the same code as with my button? Thanks in advance

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

      Hi, I would use ListBox.KeyDown event and a foreach loop over ListBox.SelectedItems to call ListBox.Remove :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


      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