Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Displaying list object properties in combo box C#
New Posts  All Forums:Forum Nav:

Displaying list object properties in combo box C#

post #1 of 5
Thread Starter 
Here's the challenge: I have a Read Only Collection of objects. The Objects are of type "Visitor", and contain properties such as last name and first name. Both last name and first name are strings.

What I want to do is display "last name, first name" in the combo box for each Object (type "Visitor") in the Read Only Collection. For anyone who doesn't know, a Read Only Collection is a lot like a list, except you can't edit it. Like the title states, it's read only.

thanks.
post #2 of 5
In the class to add stuff to your combobox add this :
Code:
for each (int i =0; i < collection.lenght;i++)
{
comboBox.Items.Add(visitor[i].getInfo());
}

in the code for Visitors create a new method (or override toString())

add this :
Code:
public string getInfo()
{
return string stringToReturn = ""+this.getLastName()+" "+this.getFirstName;
}
You need a get/set to do this :
Code:
public string getLastName()
{
return this.lastName;
}
public string setLastName(string e)
{
this.lastName = e;
}

Edited by Abs.exe - 1/10/12 at 2:06pm
post #3 of 5
i think its supposed to be ToString() not toString() but i could be wrong, at least its To in C++
i ran into a similar problem just the other day when creating a display of floats in a windows forms application label (display of a calculator)... i wound up using firstnum.ToString() and it works perfectly
Yin
(13 items)
 
Yang
(14 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i7-2600K Sandy Bridge ASUS P8Z68-V PRO PowerColor AX6950 2GBD5-2DH G.SKILL Ripjaws X Series 8GB (2 x 4GB) 
Hard DriveCoolingOSMonitor
Crucial M4 CT128M4SSD2 2.5" SSD Hyper 212 EVO Windows 7 x64 Acer V243HAJbd Black 24" 2ms(GTG) Widescreen 
KeyboardPowerCaseMouse
Microsoft SideWinder X6 Black Keyboard Win USB ... SeaSonic X Series X650 Gold XCLIO Color I Black Steel / Plastic ATX Mid Tow... Microsoft Wireless Mobile Mouse 4000 
Mouse Pad
Black Tightened Leather Circle 
CPUMotherboardGraphicsRAM
Intel Core i7-3960X Extreme Edition Sandy Bridg... ASUS Maximus IV Extreme-Z LGA 1155 Intel Z68 Asus Mars II GeForce GTX 580 x2 (Fermi) 3GB Patriot Gamer 2 Series 16GB (2 x 8GB) 
Hard DriveOptical DriveCoolingOS
OCZ RevoDrive 3 X2 series RVD3X2-FHPX4 SSD HP DVD-ROM Drive Model 481045-B21 Hyper 212 Evo x4 Windows 7 
MonitorKeyboardPowerCase
NEC Display Solutions LCD2190UXp-BK Black 21.3" x2 RAZER Black USB Wired BlackWidow Ultimate Mecha... CISCO PWR-C45-1300ACV Catalyst 4500 Series 1300... Sentey Black Box Series BX2-4292 v2.1 / 4xUSB /... 
MouseAudio
Logitech G700 Black 13 Buttons Tilt Wheel USB R... BOSE Companion 2 Series 
  hide details  
Reply
Yin
(13 items)
 
Yang
(14 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i7-2600K Sandy Bridge ASUS P8Z68-V PRO PowerColor AX6950 2GBD5-2DH G.SKILL Ripjaws X Series 8GB (2 x 4GB) 
Hard DriveCoolingOSMonitor
Crucial M4 CT128M4SSD2 2.5" SSD Hyper 212 EVO Windows 7 x64 Acer V243HAJbd Black 24" 2ms(GTG) Widescreen 
KeyboardPowerCaseMouse
Microsoft SideWinder X6 Black Keyboard Win USB ... SeaSonic X Series X650 Gold XCLIO Color I Black Steel / Plastic ATX Mid Tow... Microsoft Wireless Mobile Mouse 4000 
Mouse Pad
Black Tightened Leather Circle 
CPUMotherboardGraphicsRAM
Intel Core i7-3960X Extreme Edition Sandy Bridg... ASUS Maximus IV Extreme-Z LGA 1155 Intel Z68 Asus Mars II GeForce GTX 580 x2 (Fermi) 3GB Patriot Gamer 2 Series 16GB (2 x 8GB) 
Hard DriveOptical DriveCoolingOS
OCZ RevoDrive 3 X2 series RVD3X2-FHPX4 SSD HP DVD-ROM Drive Model 481045-B21 Hyper 212 Evo x4 Windows 7 
MonitorKeyboardPowerCase
NEC Display Solutions LCD2190UXp-BK Black 21.3" x2 RAZER Black USB Wired BlackWidow Ultimate Mecha... CISCO PWR-C45-1300ACV Catalyst 4500 Series 1300... Sentey Black Box Series BX2-4292 v2.1 / 4xUSB /... 
MouseAudio
Logitech G700 Black 13 Buttons Tilt Wheel USB R... BOSE Companion 2 Series 
  hide details  
Reply
post #4 of 5
Quote:
Originally Posted by GFreak45 View Post

i think its supposed to be ToString() not toString() but i could be wrong, at least its To in C++
i ran into a similar problem just the other day when creating a display of floats in a windows forms application label (display of a calculator)... i wound up using firstnum.ToString() and it works perfectly

I'm afraid I'm working in Java right now, toString() or ToString() as long as you understand that it calls the tostring method you should be able to figure out the way to type it if it pop an error.
post #5 of 5
i know, wasnt saying you were wrong, but if someone doesnt know that already i would assume they are still a beginner, and may have a hard time figuring that out :/
im not meaning to say, "Haw Haw you were wrong" or something... just pointing out case sensitivity
Yin
(13 items)
 
Yang
(14 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i7-2600K Sandy Bridge ASUS P8Z68-V PRO PowerColor AX6950 2GBD5-2DH G.SKILL Ripjaws X Series 8GB (2 x 4GB) 
Hard DriveCoolingOSMonitor
Crucial M4 CT128M4SSD2 2.5" SSD Hyper 212 EVO Windows 7 x64 Acer V243HAJbd Black 24" 2ms(GTG) Widescreen 
KeyboardPowerCaseMouse
Microsoft SideWinder X6 Black Keyboard Win USB ... SeaSonic X Series X650 Gold XCLIO Color I Black Steel / Plastic ATX Mid Tow... Microsoft Wireless Mobile Mouse 4000 
Mouse Pad
Black Tightened Leather Circle 
CPUMotherboardGraphicsRAM
Intel Core i7-3960X Extreme Edition Sandy Bridg... ASUS Maximus IV Extreme-Z LGA 1155 Intel Z68 Asus Mars II GeForce GTX 580 x2 (Fermi) 3GB Patriot Gamer 2 Series 16GB (2 x 8GB) 
Hard DriveOptical DriveCoolingOS
OCZ RevoDrive 3 X2 series RVD3X2-FHPX4 SSD HP DVD-ROM Drive Model 481045-B21 Hyper 212 Evo x4 Windows 7 
MonitorKeyboardPowerCase
NEC Display Solutions LCD2190UXp-BK Black 21.3" x2 RAZER Black USB Wired BlackWidow Ultimate Mecha... CISCO PWR-C45-1300ACV Catalyst 4500 Series 1300... Sentey Black Box Series BX2-4292 v2.1 / 4xUSB /... 
MouseAudio
Logitech G700 Black 13 Buttons Tilt Wheel USB R... BOSE Companion 2 Series 
  hide details  
Reply
Yin
(13 items)
 
Yang
(14 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i7-2600K Sandy Bridge ASUS P8Z68-V PRO PowerColor AX6950 2GBD5-2DH G.SKILL Ripjaws X Series 8GB (2 x 4GB) 
Hard DriveCoolingOSMonitor
Crucial M4 CT128M4SSD2 2.5" SSD Hyper 212 EVO Windows 7 x64 Acer V243HAJbd Black 24" 2ms(GTG) Widescreen 
KeyboardPowerCaseMouse
Microsoft SideWinder X6 Black Keyboard Win USB ... SeaSonic X Series X650 Gold XCLIO Color I Black Steel / Plastic ATX Mid Tow... Microsoft Wireless Mobile Mouse 4000 
Mouse Pad
Black Tightened Leather Circle 
CPUMotherboardGraphicsRAM
Intel Core i7-3960X Extreme Edition Sandy Bridg... ASUS Maximus IV Extreme-Z LGA 1155 Intel Z68 Asus Mars II GeForce GTX 580 x2 (Fermi) 3GB Patriot Gamer 2 Series 16GB (2 x 8GB) 
Hard DriveOptical DriveCoolingOS
OCZ RevoDrive 3 X2 series RVD3X2-FHPX4 SSD HP DVD-ROM Drive Model 481045-B21 Hyper 212 Evo x4 Windows 7 
MonitorKeyboardPowerCase
NEC Display Solutions LCD2190UXp-BK Black 21.3" x2 RAZER Black USB Wired BlackWidow Ultimate Mecha... CISCO PWR-C45-1300ACV Catalyst 4500 Series 1300... Sentey Black Box Series BX2-4292 v2.1 / 4xUSB /... 
MouseAudio
Logitech G700 Black 13 Buttons Tilt Wheel USB R... BOSE Companion 2 Series 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Displaying list object properties in combo box C#