473,387 Members | 1,550 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,387 software developers and data experts.

ValueMember = This ?

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.
Nov 17 '05 #1
3 3443
Tony Maresca wrote:
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
Nov 17 '05 #2
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
tr***********@gmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #3
Trint Smith wrote:
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
tr***********@gmail.com

*** Sent via Developersdex http://www.developersdex.com ***


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
Nov 17 '05 #4

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

Similar topics

2
by: Supa Hoopsa | last post by:
Working on a windows form, I am trying to bind a listbox to a dataset and want to set the displaymember & Valuemember properties of the listbox so that I can retrieve the selectedvalue from a...
1
by: Tonya | last post by:
Hi! I have a CheckedListBox, bound to a DataSet using DisplayMember and ValueMember. I need to have the ValueMember of all checked items in run time. the only way to receive ValueMember is...
1
by: Jim Heavey | last post by:
If you have a comboBox which has it's DisplayMember and ValueMenber bound to a datatable. If I know the "ValueMember" value - is there a way for me to set the index of the control to correspond...
0
by: Beringer | last post by:
I have implemented a combobox and have set the DataSource to an ArrayList. I next set the DisplayMember and ValueMember properties. When I run the code the combobox will display the proper text...
0
by: Alpha | last post by:
I am getting the following Exception error message when I assign the listbox Value to a table column in dataset. The dataset gets the tables and value from SQL table. There is no error if I...
1
by: geraldine hobley | last post by:
Hello, I wish to set the valuemember of a combobox to the value of a property in a class(projlist - see below). I wish to set the valuember of the combobox cmbstatus to the value of property...
1
by: Bruce A. Julseth | last post by:
Sorry. The other post got sent before I was complete. Does the ValueMember property in the ComboBox work like the DisplayMember property. For example, if I set the properties: ...
5
by: Spam Catcher | last post by:
Hello all, I can't seem to set the value member properly in code... I'm using a ComboBox in DropDownList mode: Private Class ApplicationsComboBoxItem Private _Name As String Private...
5
by: =?Utf-8?B?QmVu?= | last post by:
How would you add an item with its DisplayMember and ValueMember without binding to a datatable or dataview like: listbox.DisplayMember = "name"; listbox.ValueMember = "recid"; listbox.DataSource...
2
by: Cdude | last post by:
Please can anyone tell me how to display the valuemember of a combobox which is databound I have tried MessageBox.Show(Combobox1.ValueMember.ToString()) this displays the Column name to which the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.