Tag Property ComboBox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • truezplaya
    New Member
    • Jul 2007
    • 115

    Tag Property ComboBox

    Hi All

    I have another Problem. I am trying to retrieve an object from my combo box through the tag property but it's not having any of it. I populate my setOfCars as a collection like so
    Code:
     foreach (Car car in DBcars)
                    {
                        car.Tag = car ;
                        SetOfCars.Add(car);
                    }
    This collection is then returned and used to populate a comboBox

    Code:
    foreach (Car car in SetOfCars)
                {
       
                    cb_Car.Items.Add(car.Tag);
                }
    I have a override of ToString() in my class Car.

    I then want to grab the selected item in the comboBox as an object. Everything that i have tried is failing miserably. Could anyone suggest how i would go about obtaining the object from the comboBox.
  • truezplaya
    New Member
    • Jul 2007
    • 115

    #2
    I have found a solution but i am not sure why the..

    Code:
    Car.Tag
    doesn't do the same thing as i set the items Tag property to the Object

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      I'm not sure I follow the reasoning here. Maybe because so little of the total project is here.

      You are setting the tag of a car equal to the car itself. I'm not sure why this extra step. I would think if you can add car.Tag which is an object, then you could just add 'car' which is an object.
      Code:
      foreach (Car car in DBcars)
                      {
                          cb_Car.Items.Add(car);
                      }
      I do something just like this for plugins in a listbox. I'm fairly certain that a combox can take an object just like a listbox can.

      Comment

      Working...