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. rename listbox item

rename listbox item

Scheduled Pinned Locked Moved C#
csharpvisual-studiohelptutorial
5 Posts 3 Posters 1 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.
  • K Offline
    K Offline
    kennyhibs
    wrote on last edited by
    #1

    can anyone point me in the right direction on how to right click on a listbox entry and be able to rename it. my project logs video clips in 60 sec files and stores them in a folder, i use filesystemwatcher to populate a listbox of with the file names as they are created minute 1 minute 2 minute 3 and so on... i want to be able to select a file and rename it so i can find that bit of video quicker so far i got private void listBox1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) //not sure what to add here any help would be great using visual studio 2008 c# kenny

    L S 2 Replies Last reply
    0
    • K kennyhibs

      can anyone point me in the right direction on how to right click on a listbox entry and be able to rename it. my project logs video clips in 60 sec files and stores them in a folder, i use filesystemwatcher to populate a listbox of with the file names as they are created minute 1 minute 2 minute 3 and so on... i want to be able to select a file and rename it so i can find that bit of video quicker so far i got private void listBox1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) //not sure what to add here any help would be great using visual studio 2008 c# kenny

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

      Hi, 1. why use MouseDown? I would set SelectionMode.One, then use SelectedIndexChanged event and SelectedIndex property. Don't forget to check for >=0. Or better yet, use DoubleClick event, so user must double click to enter rename mode. 2. how will you enter the new name? just typing at the ListBox? trough a TextBox? and when do you want to rename? on hitting Enter? clicking a Button? :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


      I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
      [The QA section does it automatically now, I hope we soon get it on regular forums as well]


      K 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, 1. why use MouseDown? I would set SelectionMode.One, then use SelectedIndexChanged event and SelectedIndex property. Don't forget to check for >=0. Or better yet, use DoubleClick event, so user must double click to enter rename mode. 2. how will you enter the new name? just typing at the ListBox? trough a TextBox? and when do you want to rename? on hitting Enter? clicking a Button? :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


        I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
        [The QA section does it automatically now, I hope we soon get it on regular forums as well]


        K Offline
        K Offline
        kennyhibs
        wrote on last edited by
        #3

        would like to enter new name by just typing at listbox, dont want to double click as i use that for playing the video file kenny

        L 1 Reply Last reply
        0
        • K kennyhibs

          can anyone point me in the right direction on how to right click on a listbox entry and be able to rename it. my project logs video clips in 60 sec files and stores them in a folder, i use filesystemwatcher to populate a listbox of with the file names as they are created minute 1 minute 2 minute 3 and so on... i want to be able to select a file and rename it so i can find that bit of video quicker so far i got private void listBox1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) //not sure what to add here any help would be great using visual studio 2008 c# kenny

          S Offline
          S Offline
          ScottM1
          wrote on last edited by
          #4

          I would use a context menu. When the user right-clicks and selects rename you can pop up a dialog asking for the new value to be input into a textbox. When the user clicks OK you can just update the selected item text to the text they entered.

          1 Reply Last reply
          0
          • K kennyhibs

            would like to enter new name by just typing at listbox, dont want to double click as i use that for playing the video file kenny

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

            I would go with Scott's suggestion (context menu), hence use the SelectedIndexChanged event, and the KeyPress event. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


            I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
            [The QA section does it automatically now, I hope we soon get it on regular forums as well]


            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