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. Visual Basic
  4. disable a listbox item...

disable a listbox item...

Scheduled Pinned Locked Moved Visual Basic
csharp
9 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.
  • S Offline
    S Offline
    shaz jazz
    wrote on last edited by
    #1

    Hi i am working in VB.net using .net 2.0. i have a requirment to disable a listbox control's single item ....i searched msdn which says.. "You can disable an item in a list box or combo box by adding a single backslash to the beginning of the expression. " i tied the following code ListBox1.Items.Add("good") ListBox1.Items.Add("\bad") but it didn't worked and "bad" did not appeared disabled.. dispite this my requirement is to disable an item when mouse double click event occurs... hope someone will come with solution

    Faith is higher faculty than reason.. shaz jazz

    K 1 Reply Last reply
    0
    • S shaz jazz

      Hi i am working in VB.net using .net 2.0. i have a requirment to disable a listbox control's single item ....i searched msdn which says.. "You can disable an item in a list box or combo box by adding a single backslash to the beginning of the expression. " i tied the following code ListBox1.Items.Add("good") ListBox1.Items.Add("\bad") but it didn't worked and "bad" did not appeared disabled.. dispite this my requirement is to disable an item when mouse double click event occurs... hope someone will come with solution

      Faith is higher faculty than reason.. shaz jazz

      K Offline
      K Offline
      kubben
      wrote on last edited by
      #2

      A listbox contains listitems. The listitem object has an enabled property on it. Find the correct listitem and mark the enabled property to false. There is a double click event on the listbox. The sender passed it should be the listbox. You should be able to cast the sender as a listbox and get the selectedindex. Use the selected index to get the listitem and set the enabled = false. Hope that helps. Ben

      S 1 Reply Last reply
      0
      • K kubben

        A listbox contains listitems. The listitem object has an enabled property on it. Find the correct listitem and mark the enabled property to false. There is a double click event on the listbox. The sender passed it should be the listbox. You should be able to cast the sender as a listbox and get the selectedindex. Use the selected index to get the listitem and set the enabled = false. Hope that helps. Ben

        S Offline
        S Offline
        shaz jazz
        wrote on last edited by
        #3

        kubben wrote:

        The sender passed it should be the listbox. You should be able to cast the sender as a listbox and get the selectedindex. Use the selected index to get the listitem and set the enabled = false.

        but its not possible because there is no class in whichi save that item further there wasn't any need to use selectedindex for selecting item but i can use selecteditem for such purpose.. so the origanl question is as it is...

        May God help u solv ur problems as well,thx in advance!!

        K 1 Reply Last reply
        0
        • S shaz jazz

          kubben wrote:

          The sender passed it should be the listbox. You should be able to cast the sender as a listbox and get the selectedindex. Use the selected index to get the listitem and set the enabled = false.

          but its not possible because there is no class in whichi save that item further there wasn't any need to use selectedindex for selecting item but i can use selecteditem for such purpose.. so the origanl question is as it is...

          May God help u solv ur problems as well,thx in advance!!

          K Offline
          K Offline
          kubben
          wrote on last edited by
          #4

          So using SelectedItem would work fine too. inside the method you would have: DirectCast(Sender, ListBox).SelectedItem.Enable = false Pretty sure that should work. Ben

          S 1 Reply Last reply
          0
          • K kubben

            So using SelectedItem would work fine too. inside the method you would have: DirectCast(Sender, ListBox).SelectedItem.Enable = false Pretty sure that should work. Ben

            S Offline
            S Offline
            shaz jazz
            wrote on last edited by
            #5

            no its not working at all.. i did just as mentioned..it gives this exception message "Public member 'Enable' on type 'String' not found." its windows application i hope you are not misinterpretting that its web application.

            May God help u solv ur problems as well,thx in advance!!

            K 1 Reply Last reply
            0
            • S shaz jazz

              no its not working at all.. i did just as mentioned..it gives this exception message "Public member 'Enable' on type 'String' not found." its windows application i hope you are not misinterpretting that its web application.

              May God help u solv ur problems as well,thx in advance!!

              K Offline
              K Offline
              kubben
              wrote on last edited by
              #6

              Would you post your code, so I can see what you are doing? Thanks, Ben

              S 1 Reply Last reply
              0
              • K kubben

                Would you post your code, so I can see what you are doing? Thanks, Ben

                S Offline
                S Offline
                shaz jazz
                wrote on last edited by
                #7

                sure here it is: Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ListBox1.Items.Add("good") ListBox1.Items.Add("bad") End Sub then here is 2nd chunk of code: Private Sub ListBox1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseClick DirectCast(sender, ListBox).SelectedItem.Enable = False End Sub hope you'll get to the problem.

                Thanks..

                K 1 Reply Last reply
                0
                • S shaz jazz

                  sure here it is: Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ListBox1.Items.Add("good") ListBox1.Items.Add("bad") End Sub then here is 2nd chunk of code: Private Sub ListBox1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseClick DirectCast(sender, ListBox).SelectedItem.Enable = False End Sub hope you'll get to the problem.

                  Thanks..

                  K Offline
                  K Offline
                  kubben
                  wrote on last edited by
                  #8

                  Well, I guess you were right I was remembering the web control listbox. Still I think you can get something to work. The listbox has a SetSelected method on it, which takes an index and true or false if the item should be selected. So I would suggest you keep track of the index of the items that are double clicked and then on the click method check to see if they just clicked on one of the indexes that is not suppose to be selectedable and then call the SetSelected method and set that index back to false. Hope that helps. Ben

                  S 1 Reply Last reply
                  0
                  • K kubben

                    Well, I guess you were right I was remembering the web control listbox. Still I think you can get something to work. The listbox has a SetSelected method on it, which takes an index and true or false if the item should be selected. So I would suggest you keep track of the index of the items that are double clicked and then on the click method check to see if they just clicked on one of the indexes that is not suppose to be selectedable and then call the SetSelected method and set that index back to false. Hope that helps. Ben

                    S Offline
                    S Offline
                    shaz jazz
                    wrote on last edited by
                    #9

                    ok thankyou very much, your idea wud be indeed helpfull.

                    May God help u solv ur problems as well,thx in advance!!

                    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