ValueMember = This ?

T

Tony Maresca

I am binding a combo box to an ArrayList of
objects with a property called "Name" that is
assigned to DisplayMember.

How can I have the SelectedValue of the combo
return the instance of the object whose Name
property is selected in the combo?

I know that I can add a property like this:

public class MyObject
{
public MyObject Value {get{return this;}}
}

And set ValueMember to "Value".

But, I was wondering if there was any special
designation I could just set ValueMember to,
since I don't always work with my own objects
or non-sealed objects, and hence, can't always
add the property.

--
Tony M.
 
H

Hans Kesting

Tony said:
I am binding a combo box to an ArrayList of
objects with a property called "Name" that is
assigned to DisplayMember.

How can I have the SelectedValue of the combo
return the instance of the object whose Name
property is selected in the combo?

I know that I can add a property like this:

public class MyObject
{
public MyObject Value {get{return this;}}
}

And set ValueMember to "Value".

But, I was wondering if there was any special
designation I could just set ValueMember to,
since I don't always work with my own objects
or non-sealed objects, and hence, can't always
add the property.

do you want the SelectedItem property?

Hans Kesting
 
T

Trint Smith

Hans,
I don't know. I'm not sure I understand where I would need that in
Control.Invoke. But I am anxious to see your example.
Thanks,
Trint

.Net programmer
(e-mail address removed)
 
H

Hans Kesting

Trint said:
Hans,
I don't know. I'm not sure I understand where I would need that in
Control.Invoke. But I am anxious to see your example.
Thanks,
Trint

Net programmer
(e-mail address removed)

I meant, instead of trying to get SelectedValue to return the item,
you could use SelectedItem which already returns the selected item
(as an "object").

Hans Kesting
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top