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. ToolStripSeperator to a ToolStripMenuItem

ToolStripSeperator to a ToolStripMenuItem

Scheduled Pinned Locked Moved C#
helpquestion
4 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.
  • G Offline
    G Offline
    Gareth H
    wrote on last edited by
    #1

    Hi, I go through a collection of toolstripmenuitems and if its the correct item, i set it to be checked. foreach (ToolStripMenuItem sortItemDropDown in sortItem.DropDownItems) { if (sortItemDropDown.Name.Equals(tickSortBy)) { sortItemDropDown.Checked = true; } } The problem is that the sortedItem.DropDownItems has a Seperator in it, thus i get an exception telling me i cant convert a seperator to a menuitem. Is there a work-around ? Regards, Gareth.

    S S 2 Replies Last reply
    0
    • G Gareth H

      Hi, I go through a collection of toolstripmenuitems and if its the correct item, i set it to be checked. foreach (ToolStripMenuItem sortItemDropDown in sortItem.DropDownItems) { if (sortItemDropDown.Name.Equals(tickSortBy)) { sortItemDropDown.Checked = true; } } The problem is that the sortedItem.DropDownItems has a Seperator in it, thus i get an exception telling me i cant convert a seperator to a menuitem. Is there a work-around ? Regards, Gareth.

      S Offline
      S Offline
      Stefan Troschuetz
      wrote on last edited by
      #2

      In the foreach loop use the common base type ToolStripItem and only cast to a ToolStripMenuItem if the current item is really a ToolStripMenuItem.

      foreach (ToolStripItem sortItemDropDown in sortItem.DropDownItems)
      {
      if (sortItemDropDown.Name.Equals(tickSortBy) && (sortItemDropDown is ToolStripMenuItem))
      {
      ((ToolStripMenuItem) sortItemDropDown).Checked = true;
      }
      }


      "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

      www.troschuetz.de

      G 1 Reply Last reply
      0
      • G Gareth H

        Hi, I go through a collection of toolstripmenuitems and if its the correct item, i set it to be checked. foreach (ToolStripMenuItem sortItemDropDown in sortItem.DropDownItems) { if (sortItemDropDown.Name.Equals(tickSortBy)) { sortItemDropDown.Checked = true; } } The problem is that the sortedItem.DropDownItems has a Seperator in it, thus i get an exception telling me i cant convert a seperator to a menuitem. Is there a work-around ? Regards, Gareth.

        S Offline
        S Offline
        Sven Cipido
        wrote on last edited by
        #3

        You can check on the type of the toolstripmenuitem. For the separator this is System.Windows.Forms.ToolStripSeparator.

        1 Reply Last reply
        0
        • S Stefan Troschuetz

          In the foreach loop use the common base type ToolStripItem and only cast to a ToolStripMenuItem if the current item is really a ToolStripMenuItem.

          foreach (ToolStripItem sortItemDropDown in sortItem.DropDownItems)
          {
          if (sortItemDropDown.Name.Equals(tickSortBy) && (sortItemDropDown is ToolStripMenuItem))
          {
          ((ToolStripMenuItem) sortItemDropDown).Checked = true;
          }
          }


          "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

          www.troschuetz.de

          G Offline
          G Offline
          Gareth H
          wrote on last edited by
          #4

          Thanks. Regards, Gareth.

          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