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. Combobox in C# : how to add for each Item a Tag ?

Combobox in C# : how to add for each Item a Tag ?

Scheduled Pinned Locked Moved C#
csharptutorialquestion
4 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.
  • Y Offline
    Y Offline
    youssef
    wrote on last edited by
    #1

    Hi, I looking to storing some datas to a combobox with for each datas a would like to store a Tag value. Best regrads youssef

    S H L 3 Replies Last reply
    0
    • Y youssef

      Hi, I looking to storing some datas to a combobox with for each datas a would like to store a Tag value. Best regrads youssef

      S Offline
      S Offline
      Skynyrd
      wrote on last edited by
      #2

      Create a custom object collection where your objects show all the info u need through properties. Then set the collection as ur combo's datasource and set the displaymember and valuemember to your object's properties (Name and Tag for example). If u dont want to go through all that, it might be easier to just store all objects + info in the necessary fields of a datatable (that would solve ur custom object collection) and proceed the same way as before.

      1 Reply Last reply
      0
      • Y youssef

        Hi, I looking to storing some datas to a combobox with for each datas a would like to store a Tag value. Best regrads youssef

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        For more information and an example of what Skynyrd mentioned, read about the MappingName Property[^] for the DataGridTableStyle class in the .NET Framework SDK. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]

        1 Reply Last reply
        0
        • Y youssef

          Hi, I looking to storing some datas to a combobox with for each datas a would like to store a Tag value. Best regrads youssef

          L Offline
          L Offline
          Luis Alonso Ramos
          wrote on last edited by
          #4

          You can add any object as an item to a ComboBox, and to display it, the ComboBox calls the object's ToString method. So, create a MyComboItem class that contians two (or more) properties, Text and Tag, and override ToString to return the contents of the Text property. When you get an item from the ComboBox's Items collection, don't forget to do the appropiate cast. -- LuisR


          Luis Alonso Ramos Intelectix - Chihuahua, Mexico Not much here: My CP Blog!

          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