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. C#
  4. Combobox

Combobox

Scheduled Pinned Locked Moved C#
questioncsharptutorial
9 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.
  • S Offline
    S Offline
    SpeBeeTo
    wrote on last edited by
    #1

    Hi. I am a newbie in programming C#, and am having a mental block. I am programming for the pocketPC. I have a Combobox named "Type" and have a list there. I want to show the results of the entry from the combobox into a text label. For example, I pick "fruit" from the combobox. I want to display on the screen: "This food is a fruit" If I pick "vegetable" from the combobox, it should display: "This food is a vegetable" Right now, I'm getting: "This food is a 1" "This food is a 2" How can I make the 2 into vegetable? This is what I have, and I have a feeling it has to do with the GetValue and/or GetOrdinal.... I just can't seem to get it to work.... TypeLabel.Text = rReader.GetValue(rReader.GetOrdinal("MovieType")).ToString(); Thanks... Sorry for such a dumb question. :sigh: If I haven't given you enough code, let me know. I can always add more. :laugh:

    A S 2 Replies Last reply
    0
    • S SpeBeeTo

      Hi. I am a newbie in programming C#, and am having a mental block. I am programming for the pocketPC. I have a Combobox named "Type" and have a list there. I want to show the results of the entry from the combobox into a text label. For example, I pick "fruit" from the combobox. I want to display on the screen: "This food is a fruit" If I pick "vegetable" from the combobox, it should display: "This food is a vegetable" Right now, I'm getting: "This food is a 1" "This food is a 2" How can I make the 2 into vegetable? This is what I have, and I have a feeling it has to do with the GetValue and/or GetOrdinal.... I just can't seem to get it to work.... TypeLabel.Text = rReader.GetValue(rReader.GetOrdinal("MovieType")).ToString(); Thanks... Sorry for such a dumb question. :sigh: If I haven't given you enough code, let me know. I can always add more. :laugh:

      A Offline
      A Offline
      albCode
      wrote on last edited by
      #2

      try this on comboBox1_SelectedIndexChanged event write this code this.textBox1.Text = this.comboBox1.Text; //each item u select from combobox the text of selected index should appear in textbox I hope this helps

      S 1 Reply Last reply
      0
      • A albCode

        try this on comboBox1_SelectedIndexChanged event write this code this.textBox1.Text = this.comboBox1.Text; //each item u select from combobox the text of selected index should appear in textbox I hope this helps

        S Offline
        S Offline
        SpeBeeTo
        wrote on last edited by
        #3

        Thank you so much! I will try it out immediately and let you know! Thanks again! :-D

        A 1 Reply Last reply
        0
        • S SpeBeeTo

          Thank you so much! I will try it out immediately and let you know! Thanks again! :-D

          A Offline
          A Offline
          albCode
          wrote on last edited by
          #4

          Never Mind dude we are here to helps each-others :cool:

          S 1 Reply Last reply
          0
          • A albCode

            Never Mind dude we are here to helps each-others :cool:

            S Offline
            S Offline
            SpeBeeTo
            wrote on last edited by
            #5

            Okay, I thought I understood what I'm doing, but it's not really working. :confused: I added this: this.GLabel.Text = this.TypeCombo.Text; To the Windows Form Designer generated code. I added this: OnTypeCombo_SelectedIndexChanged "1" write male; It gives me the following error: Invalid token "1" in class, struct, or interface member declaration. :((

            T A S 3 Replies Last reply
            0
            • S SpeBeeTo

              Okay, I thought I understood what I'm doing, but it's not really working. :confused: I added this: this.GLabel.Text = this.TypeCombo.Text; To the Windows Form Designer generated code. I added this: OnTypeCombo_SelectedIndexChanged "1" write male; It gives me the following error: Invalid token "1" in class, struct, or interface member declaration. :((

              T Offline
              T Offline
              tatchung
              wrote on last edited by
              #6

              Hello! Oh my bad...try this in windows for designer: this.combobox1.SelectedIndexChanged += new System.EventHandler(this.combobox1_SelectedIndexChanged); then have this code inside the EventArgs: this.Label.Text = this.combobox1.SelectedItem.Text hope that works:-O Aim small, miss small... -- modified at 1:02 Thursday 15th December, 2005

              1 Reply Last reply
              0
              • S SpeBeeTo

                Okay, I thought I understood what I'm doing, but it's not really working. :confused: I added this: this.GLabel.Text = this.TypeCombo.Text; To the Windows Form Designer generated code. I added this: OnTypeCombo_SelectedIndexChanged "1" write male; It gives me the following error: Invalid token "1" in class, struct, or interface member declaration. :((

                A Offline
                A Offline
                albCode
                wrote on last edited by
                #7

                private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e) { this.textBox1.Text = this.comboBox1.Text; } //this code must work, i tested multiple time and works fine. I hope u fill combobox in onLoad Event of ur Form or u fill combobox from another event

                1 Reply Last reply
                0
                • S SpeBeeTo

                  Okay, I thought I understood what I'm doing, but it's not really working. :confused: I added this: this.GLabel.Text = this.TypeCombo.Text; To the Windows Form Designer generated code. I added this: OnTypeCombo_SelectedIndexChanged "1" write male; It gives me the following error: Invalid token "1" in class, struct, or interface member declaration. :((

                  S Offline
                  S Offline
                  SpeBeeTo
                  wrote on last edited by
                  #8

                  Thanks guys! Off to the new "challenge"!!!! :)

                  1 Reply Last reply
                  0
                  • S SpeBeeTo

                    Hi. I am a newbie in programming C#, and am having a mental block. I am programming for the pocketPC. I have a Combobox named "Type" and have a list there. I want to show the results of the entry from the combobox into a text label. For example, I pick "fruit" from the combobox. I want to display on the screen: "This food is a fruit" If I pick "vegetable" from the combobox, it should display: "This food is a vegetable" Right now, I'm getting: "This food is a 1" "This food is a 2" How can I make the 2 into vegetable? This is what I have, and I have a feeling it has to do with the GetValue and/or GetOrdinal.... I just can't seem to get it to work.... TypeLabel.Text = rReader.GetValue(rReader.GetOrdinal("MovieType")).ToString(); Thanks... Sorry for such a dumb question. :sigh: If I haven't given you enough code, let me know. I can always add more. :laugh:

                    S Offline
                    S Offline
                    SpeBeeTo
                    wrote on last edited by
                    #9

                    Well, it worked. :) Thanks again. I have another problem, errr, challenge now. I am using an SQL database to save the info the person chooses on one form (pedbone.cs). Here's the code to the Combobox I've got on the "main" form (pedbone.cs): // populate the list - gender m_cTypes = new ArrayList(); m_cTypes.Add("Unknown"); m_cTypes.Add("Male"); m_cTypes.Add("Female"); TypeCombo.DataSource = m_cTypes; These are listed in a ListView SqlCeCommand sqlLoadEvents = m_cConn.CreateCommand(); sqlLoadEvents.CommandText = szSQL; SqlCeDataReader rReader = sqlLoadEvents.ExecuteReader(); while ( rReader.Read() ) { lvItem.SubItems.Add(GetTypeFromNumber ((int)rReader.GetValue(rReader.GetOrdinal("MovieType"))));// Gender CollectionList.Items.Add( lvItem ); } } And here I got the Combobox text to show in the ListView, by using this code private string GetTypeFromNumber(int nTypeID) { return (m_cTypes[nTypeID].ToString()); } Now, when you click on the listview item, a new form opens up (AddEditMovieForm.cs) to view the file in more detail. And here's where I'm running into a bit of a bind. public AddEditMovieForm(SqlCeConnection cConn, int nMovieID) { InitializeComponent(); m_cConn = cConn; m_nMovieID = nMovieID; m_cTypes = new ArrayList(); if ( m_nMovieID != -1 ) { SqlCeCommand sqlCommand = m_cConn.CreateCommand(); sqlCommand.CommandText = "SELECT * FROM MOVIE_MNGR_TABLE where MovieID = "+m_nMovieID.ToString(); SqlCeDataReader rReader = sqlCommand.ExecuteReader(); if ( rReader.Read() ) { } { GenderLabel.Text = rReader.GetValue(rReader.GetOrdinal("MovieType")).ToString();// Gender { } } } }

                    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