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. Disabled some items in ListView

Disabled some items in ListView

Scheduled Pinned Locked Moved C#
question
5 Posts 3 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.
  • F Offline
    F Offline
    fjlv2005
    wrote on last edited by
    #1

    Good day to all, I have a Listview that contains a list of connected/disconnected computers. I want to disables those items in the listview which are disconnected so that users wount be able to select or perform right click on this disconnected items. How can we disable some items in listview? Thanks a lot.

    A M 2 Replies Last reply
    0
    • F fjlv2005

      Good day to all, I have a Listview that contains a list of connected/disconnected computers. I want to disables those items in the listview which are disconnected so that users wount be able to select or perform right click on this disconnected items. How can we disable some items in listview? Thanks a lot.

      A Offline
      A Offline
      Ahmad Mahmoud candseeme
      wrote on last edited by
      #2

      Hi & Good day to you too what do you mean by disable some items !! it is up to you not to give the user a specific action in a specific item here is an example void SetDisabled ( ListView MyView ) { ListViewItem MyItem = new ListViewItem ( ); MyItem.Text = " First Col"; MyItem.SubItems.Add( "Second Col", Color.Red, Color.Yellow, new Font ( "Tahoma", 9F ) ); MyItem.SubItems.Add ("Third Col"); MyView.Items.Add ( MyItem ); if ( MyView.Items [0].SubItems[1].ForeColor == Color.Red || MyView.Items [0].SubItems[2].Text == "Third Col" ) { //put your code here } Ahmad Shaban

      F 1 Reply Last reply
      0
      • F fjlv2005

        Good day to all, I have a Listview that contains a list of connected/disconnected computers. I want to disables those items in the listview which are disconnected so that users wount be able to select or perform right click on this disconnected items. How can we disable some items in listview? Thanks a lot.

        M Offline
        M Offline
        mav northwind
        wrote on last edited by
        #3

        Hi! Unless you're willing to rewrite the ListView there's no such thing as a disabled item per se. So you'll have to manage the information which items you consider "disabled" yourself (for example by assigning something to the item's Tag property). But you can subscribe to the SelectionChanged event or the MouseClick event and then act differently depending on the state of the item, for example removing the selection (so that "disabled" items cannot be selected) or showing a different context menu for these items. Regards, mav -- Black holes are the places where god divided by 0...

        F 1 Reply Last reply
        0
        • A Ahmad Mahmoud candseeme

          Hi & Good day to you too what do you mean by disable some items !! it is up to you not to give the user a specific action in a specific item here is an example void SetDisabled ( ListView MyView ) { ListViewItem MyItem = new ListViewItem ( ); MyItem.Text = " First Col"; MyItem.SubItems.Add( "Second Col", Color.Red, Color.Yellow, new Font ( "Tahoma", 9F ) ); MyItem.SubItems.Add ("Third Col"); MyView.Items.Add ( MyItem ); if ( MyView.Items [0].SubItems[1].ForeColor == Color.Red || MyView.Items [0].SubItems[2].Text == "Third Col" ) { //put your code here } Ahmad Shaban

          F Offline
          F Offline
          fjlv2005
          wrote on last edited by
          #4

          Thanks for your ideas. its good. it work.

          1 Reply Last reply
          0
          • M mav northwind

            Hi! Unless you're willing to rewrite the ListView there's no such thing as a disabled item per se. So you'll have to manage the information which items you consider "disabled" yourself (for example by assigning something to the item's Tag property). But you can subscribe to the SelectionChanged event or the MouseClick event and then act differently depending on the state of the item, for example removing the selection (so that "disabled" items cannot be selected) or showing a different context menu for these items. Regards, mav -- Black holes are the places where god divided by 0...

            F Offline
            F Offline
            fjlv2005
            wrote on last edited by
            #5

            Hi, thanks for the additional info. I really Appreciate it. Thanks to all of you guys who helped me. More power to 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