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. Other Discussions
  3. The Weird and The Wonderful
  4. Set selected value...

Set selected value...

Scheduled Pinned Locked Moved The Weird and The Wonderful
tutorialcsharpasp-netcomsysadmin
8 Posts 4 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
    Sandeep Mewara
    wrote on last edited by
    #1

    On asking 'how to select value from a combobox based on another combobox selected value', following was replied as one way:

    // This code only works if you know how many items are in each collection.
    private void m_CmbBox1_SelectedIndexChanged(Object Sender EventArgs e)
    {
    switch(m_CmbBox1.SelectedIndex)
    {
    case 0:
    m_CmbBox2.SelectedIndex = 0;
    break;
    case 1:
    m_CmbBox2.SelectedIndex = 1;
    break;
    case 2:
    m_CmbBox2.SelectedIndex = 2;
    break;
    default:
    m_CmbBox2.SelectedIndex = m_CmbBox2.Items.Count - 1;
    }
    }

    :doh: Got to read a comment on this, to which I fully agree: A bright example of anti-programming!

    Sandeep Mewara [My last article]: Server side Delimiters in ASP.NET[^]

    F OriginalGriffO V 3 Replies Last reply
    0
    • S Sandeep Mewara

      On asking 'how to select value from a combobox based on another combobox selected value', following was replied as one way:

      // This code only works if you know how many items are in each collection.
      private void m_CmbBox1_SelectedIndexChanged(Object Sender EventArgs e)
      {
      switch(m_CmbBox1.SelectedIndex)
      {
      case 0:
      m_CmbBox2.SelectedIndex = 0;
      break;
      case 1:
      m_CmbBox2.SelectedIndex = 1;
      break;
      case 2:
      m_CmbBox2.SelectedIndex = 2;
      break;
      default:
      m_CmbBox2.SelectedIndex = m_CmbBox2.Items.Count - 1;
      }
      }

      :doh: Got to read a comment on this, to which I fully agree: A bright example of anti-programming!

      Sandeep Mewara [My last article]: Server side Delimiters in ASP.NET[^]

      F Offline
      F Offline
      fjdiewornncalwe
      wrote on last edited by
      #2

      I saw that one too, but was too distracted to notice the stupidity in it at the time. +5...

      I wasn't, now I am, then I won't be anymore.

      S 1 Reply Last reply
      0
      • S Sandeep Mewara

        On asking 'how to select value from a combobox based on another combobox selected value', following was replied as one way:

        // This code only works if you know how many items are in each collection.
        private void m_CmbBox1_SelectedIndexChanged(Object Sender EventArgs e)
        {
        switch(m_CmbBox1.SelectedIndex)
        {
        case 0:
        m_CmbBox2.SelectedIndex = 0;
        break;
        case 1:
        m_CmbBox2.SelectedIndex = 1;
        break;
        case 2:
        m_CmbBox2.SelectedIndex = 2;
        break;
        default:
        m_CmbBox2.SelectedIndex = m_CmbBox2.Items.Count - 1;
        }
        }

        :doh: Got to read a comment on this, to which I fully agree: A bright example of anti-programming!

        Sandeep Mewara [My last article]: Server side Delimiters in ASP.NET[^]

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        If you didn't laugh, you'd cry... :sigh:

        Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        S 1 Reply Last reply
        0
        • F fjdiewornncalwe

          I saw that one too, but was too distracted to notice the stupidity in it at the time. +5...

          I wasn't, now I am, then I won't be anymore.

          S Offline
          S Offline
          Sandeep Mewara
          wrote on last edited by
          #4

          Okie! I just thought of sharing it here. Who knows someone might be implementing something like this somewhere. ;)

          Sandeep Mewara [My last article]: Server side Delimiters in ASP.NET[^]

          1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            If you didn't laugh, you'd cry... :sigh:

            Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

            S Offline
            S Offline
            Sandeep Mewara
            wrote on last edited by
            #5

            :-D What did you do?

            Sandeep Mewara [My last article]: Server side Delimiters in ASP.NET[^]

            OriginalGriffO 1 Reply Last reply
            0
            • S Sandeep Mewara

              :-D What did you do?

              Sandeep Mewara [My last article]: Server side Delimiters in ASP.NET[^]

              OriginalGriffO Offline
              OriginalGriffO Offline
              OriginalGriff
              wrote on last edited by
              #6

              A bit of both!

              Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
              "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

              1 Reply Last reply
              0
              • S Sandeep Mewara

                On asking 'how to select value from a combobox based on another combobox selected value', following was replied as one way:

                // This code only works if you know how many items are in each collection.
                private void m_CmbBox1_SelectedIndexChanged(Object Sender EventArgs e)
                {
                switch(m_CmbBox1.SelectedIndex)
                {
                case 0:
                m_CmbBox2.SelectedIndex = 0;
                break;
                case 1:
                m_CmbBox2.SelectedIndex = 1;
                break;
                case 2:
                m_CmbBox2.SelectedIndex = 2;
                break;
                default:
                m_CmbBox2.SelectedIndex = m_CmbBox2.Items.Count - 1;
                }
                }

                :doh: Got to read a comment on this, to which I fully agree: A bright example of anti-programming!

                Sandeep Mewara [My last article]: Server side Delimiters in ASP.NET[^]

                V Offline
                V Offline
                VallarasuS
                wrote on last edited by
                #7

                Sandeep Mewara wrote:

                default: m_CmbBox2.SelectedIndex = m_CmbBox2.Items.Count - 1;

                The items are not in common! But still the other cases can be avoided when the index falls with in the count. Am i making sense?! :confused: ...

                Regards Vallarasu S | FSharpMe.blogspot.com

                S 1 Reply Last reply
                0
                • V VallarasuS

                  Sandeep Mewara wrote:

                  default: m_CmbBox2.SelectedIndex = m_CmbBox2.Items.Count - 1;

                  The items are not in common! But still the other cases can be avoided when the index falls with in the count. Am i making sense?! :confused: ...

                  Regards Vallarasu S | FSharpMe.blogspot.com

                  S Offline
                  S Offline
                  Sandeep Mewara
                  wrote on last edited by
                  #8

                  Don't ask. I have no idea how this default condition was thought of! :doh:

                  Sandeep Mewara [My last article]: Server side Delimiters in ASP.NET[^]

                  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