473,322 Members | 1,806 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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

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.
Jun 13 '06 #1
3 1134
cast the SelectedItem back to your known type:

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

Marc
Jun 13 '06 #2
"james" <ja***@com.com> 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/
Jun 13 '06 #3

"Barry Kelly" <ba***********@gmail.com> wrote in message
news:c3********************************@4ax.com...
"james" <ja***@com.com> 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.
Jun 13 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Malcolm Cook | last post by:
Hi, I've created and installed a custom UDF to populate my combobox, and have defined it per :...
7
by: Donald Grove | last post by:
Is it possible to retrieve field properties from a table in access2000 using code? I have tried: " dim dbs as dao.database dim tbl as dao.tabledef dim fld as dao.field dim prop as...
2
by: Greg Strong | last post by:
Hello All, Is it possible to change table field lookup properties in code? I've been able to change other field properties in code, however so far no luck with field lookup properties. What...
3
by: evenlater | last post by:
Using Access 2007, I've found that combo box back colors change to transparent from normal inconsistently for no reason I can discern. Never had that problem in previous versions of Access. I do...
0
by: hannahhhh1056 | last post by:
Hello! I´m trying to create a makro that finds the text in a wddocument formatted as "heading 1" and then puts it in the document properties. I know how to get the text into doc properties but i...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.