PC Review


Reply
Thread Tools Rate Thread

How do I get back the properties of my object in a combo box?

 
 
james
Guest
Posts: n/a
 
      13th Jun 2006
I declared a class with 4 string properties, one of which overrides the
"toString()" method.
I add objects based on this to a combobox, and I can see the properties if I
pause execution and look at the "SelectedItem" I can see my
properties/values in the debugger, but if I try it in the code I can only
see the Equals, GetHashCode, GetType and ToString methods.

How can I access the other properties I defined?

Ta,
James.


 
Reply With Quote
 
 
 
 
Marc Gravell
Guest
Posts: n/a
 
      13th Jun 2006
cast the SelectedItem back to your known type:

MyClass myObj = combo.SelectedItem as MyClass;
if(myObj!=null) {
// do something interesting
}

Marc


 
Reply With Quote
 
Barry Kelly
Guest
Posts: n/a
 
      13th Jun 2006
"james" <(E-Mail Removed)> wrote:

> I declared a class with 4 string properties, one of which overrides the
> "toString()" method.
> I add objects based on this to a combobox, and I can see the properties if I
> pause execution and look at the "SelectedItem" I can see my
> properties/values in the debugger, but if I try it in the code I can only
> see the Equals, GetHashCode, GetType and ToString methods.
>
> How can I access the other properties I defined?


You need to typecast the SelectedItem value to your class:

((YourClassNameHere) comboBox.SelectedItem).YourPropertyHere

or

YourClassNameHere value = (YourClassNameHere) comboBox.SelectedItem;
// work with value

-- Barry

--
http://barrkel.blogspot.com/
 
Reply With Quote
 
james
Guest
Posts: n/a
 
      13th Jun 2006

"Barry Kelly" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "james" <(E-Mail Removed)> wrote:
>
>> I declared a class with 4 string properties, one of which overrides the
>> "toString()" method.
>> I add objects based on this to a combobox, and I can see the properties
>> if I
>> pause execution and look at the "SelectedItem" I can see my
>> properties/values in the debugger, but if I try it in the code I can only
>> see the Equals, GetHashCode, GetType and ToString methods.
>>
>> How can I access the other properties I defined?

>
> You need to typecast the SelectedItem value to your class:
>
> ((YourClassNameHere) comboBox.SelectedItem).YourPropertyHere
>
> or
>
> YourClassNameHere value = (YourClassNameHere) comboBox.SelectedItem;
> // work with value
>



Thanks to both of you, working now!
James.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deserialization - Can see object properties in Visual Studiointellisense but receive object refernce not set error. YZ Microsoft C# .NET 0 27th Jun 2011 09:19 AM
Re: continuous - want to change properties of object based on another object data Allen Browne Microsoft Access Form Coding 0 18th Jun 2008 04:04 AM
How to access combo box properties of DataGridView combo column Steve Marshall Microsoft Dot NET Framework Forms 2 26th Jun 2007 01:56 PM
readonly properties when displaying an object's properties in propertygrid movieknight@gmail.com Microsoft VB .NET 0 14th May 2006 06:48 AM
How to access intrinsic WScript object properties from a .NET COM object Alek Davis Microsoft C# .NET 6 13th Aug 2004 09:58 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:10 PM.