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. quick combobox question

quick combobox question

Scheduled Pinned Locked Moved C#
questiontutorial
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.
  • R Offline
    R Offline
    Ronni Marker
    wrote on last edited by
    #1

    it's 00:30 and I lost my mind in a few beers, came home and would do some coding before I hit the showers, but now I forgot an important part... I remember how to add values and text to a combobox via a datasource, but can any remember how to add both text and value in a static way? ie. Combobox1.Items.Add(new ????("text","value")); yes, yes I know, don't code drunk.

    L 1 Reply Last reply
    0
    • R Ronni Marker

      it's 00:30 and I lost my mind in a few beers, came home and would do some coding before I hit the showers, but now I forgot an important part... I remember how to add values and text to a combobox via a datasource, but can any remember how to add both text and value in a static way? ie. Combobox1.Items.Add(new ????("text","value")); yes, yes I know, don't code drunk.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      http://social.msdn.microsoft.com/forums/en-US/winforms/thread/c7a82a6a-763e-424b-84e0-496caa9cfb4d/[^]

      R 1 Reply Last reply
      0
      • L Lost User

        http://social.msdn.microsoft.com/forums/en-US/winforms/thread/c7a82a6a-763e-424b-84e0-496caa9cfb4d/[^]

        R Offline
        R Offline
        Ronni Marker
        wrote on last edited by
        #3

        nah can't really use that solution, then I wouldnt be able to use SelectedValue to get the current selected value and would have to rewrite too much code as I then couldnt load the combobox values elsewhere. but thanks for the effort.

        P 1 Reply Last reply
        0
        • R Ronni Marker

          nah can't really use that solution, then I wouldnt be able to use SelectedValue to get the current selected value and would have to rewrite too much code as I then couldnt load the combobox values elsewhere. but thanks for the effort.

          P Offline
          P Offline
          PunkIsNotDead
          wrote on last edited by
          #4

          Why don't you create a static datatable with your static data??

          static DataTable dt = new DataTable();
          public Form1()
          {
          InitializeComponent();
          dt.Columns.Add("MyTextToShow");
          dt.Columns.Add("MyValueToShow");
          dt.Rows.Add("OneText", 1);
          dt.Rows.Add("TwoText", 2);
          dt.Rows.Add("ThreeText", 3);
          comboBox1.DataSource = dt;
          comboBox1.ValueMember = "MyValueToShow";
          comboBox1.DisplayMember = "MyTextToShow";
          }

          regards... and don't code drunk! is hateful haha

          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