473,324 Members | 2,214 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,324 software developers and data experts.

Storing objects in Combo and List box

jay
I have a structure:
public struct DATA_PAIR
{
public int ID;
public string Value;
public DATA_PAIR(int id, string val)
{
this.ID = id;
this.Value = val;
}
}

I have a combo box and I'm adding items:

....
ArrayList locations = new ArrayList();
locations.Add(new ORCASettings.Common.DATA_PAIR(0, ""));
while (Reader.Read())
{
locations.Add(new ORCASettings.Common.DATA_PAIR((int)Reader[0],
Reader[9].ToString()));
}
cboLocation.ValueMember = "ID" ;
cboLocation.DisplayMember = "Value";
cboLocation.DataSource = locations;
....
....but this doesn't work. ValueMember and DisplayMember don't get affected.
What I get in my combo box is Type of the objects: ClassName+DATA_PAIR.

Thanks,
h
Nov 16 '05 #1
3 1903
Hi Jay,

You need to define ID and Value as public properties of DATA_PAIR, rather
than public fields - makes for better encapsulation too.

Joe
--
Joe Mayo, Author/Instructor
Need C#/.NET training?
visit www.mayosoftware.com
C# Tutorial - www.csharp-station.com
"jay" <so***@nospam.com> wrote in message news:cd**********@bagan.srce.hr...
I have a structure:
public struct DATA_PAIR
{
public int ID;
public string Value;
public DATA_PAIR(int id, string val)
{
this.ID = id;
this.Value = val;
}
}

I have a combo box and I'm adding items:

...
ArrayList locations = new ArrayList();
locations.Add(new ORCASettings.Common.DATA_PAIR(0, ""));
while (Reader.Read())
{
locations.Add(new ORCASettings.Common.DATA_PAIR((int)Reader[0],
Reader[9].ToString()));
}
cboLocation.ValueMember = "ID" ;
cboLocation.DisplayMember = "Value";
cboLocation.DataSource = locations;
...
...but this doesn't work. ValueMember and DisplayMember don't get affected. What I get in my combo box is Type of the objects: ClassName+DATA_PAIR.

Thanks,
h

Nov 16 '05 #2
Hi Jay,

You need to define ID and Value as public properties of DATA_PAIR, rather
than public fields - makes for better encapsulation too.

Joe
--
Joe Mayo, Author/Instructor
Need C#/.NET training?
visit www.mayosoftware.com
C# Tutorial - www.csharp-station.com
"jay" <so***@nospam.com> wrote in message news:cd**********@bagan.srce.hr...
I have a structure:
public struct DATA_PAIR
{
public int ID;
public string Value;
public DATA_PAIR(int id, string val)
{
this.ID = id;
this.Value = val;
}
}

I have a combo box and I'm adding items:

...
ArrayList locations = new ArrayList();
locations.Add(new ORCASettings.Common.DATA_PAIR(0, ""));
while (Reader.Read())
{
locations.Add(new ORCASettings.Common.DATA_PAIR((int)Reader[0],
Reader[9].ToString()));
}
cboLocation.ValueMember = "ID" ;
cboLocation.DisplayMember = "Value";
cboLocation.DataSource = locations;
...
...but this doesn't work. ValueMember and DisplayMember don't get affected. What I get in my combo box is Type of the objects: ClassName+DATA_PAIR.

Thanks,
h

Nov 16 '05 #3
jay
Thanks, it works now!

"Joe Mayo [C# MVP]" <jmayo@.n0***@m.csharp-station.com> wrote in message
news:eK*************@TK2MSFTNGP12.phx.gbl...
Hi Jay,

You need to define ID and Value as public properties of DATA_PAIR, rather
than public fields - makes for better encapsulation too.

Joe
--
Joe Mayo, Author/Instructor
Need C#/.NET training?
visit www.mayosoftware.com
C# Tutorial - www.csharp-station.com
"jay" <so***@nospam.com> wrote in message

news:cd**********@bagan.srce.hr...
I have a structure:
public struct DATA_PAIR
{
public int ID;
public string Value;
public DATA_PAIR(int id, string val)
{
this.ID = id;
this.Value = val;
}
}

I have a combo box and I'm adding items:

...
ArrayList locations = new ArrayList();
locations.Add(new ORCASettings.Common.DATA_PAIR(0, ""));
while (Reader.Read())
{
locations.Add(new ORCASettings.Common.DATA_PAIR((int)Reader[0],
Reader[9].ToString()));
}
cboLocation.ValueMember = "ID" ;
cboLocation.DisplayMember = "Value";
cboLocation.DataSource = locations;
...
...but this doesn't work. ValueMember and DisplayMember don't get

affected.
What I get in my combo box is Type of the objects: ClassName+DATA_PAIR.

Thanks,
h


Nov 16 '05 #4

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

Similar topics

2
by: travlintom | last post by:
Dim intCurID As Integer *** outside of code and available to all *** Dim strConnectionString As String = _ "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=C:\Databases\ClientAppDB.mdb;"...
4
by: Heather | last post by:
Hi I am desparately looking for advice in relation to storing the results after selecting items from two combo boxes on a Referral form. The first combo box 'ctl Type' displays a full list of...
10
by: Diego F. | last post by:
Hello. I need to store custom objects in a SQL Server 2000 table. Which is the easiest way to do it? Do I need to write methods to store each attribute separately from C# app to the table and the...
0
by: jay | last post by:
I have a structure: public struct DATA_PAIR { public int ID; public string Value; public DATA_PAIR(int id, string val) { this.ID = id;
2
by: Mothi Kannan | last post by:
Hi, In vb.net I have created two combo box, dynamically and filled list in the first combo. How can I fill the Selected index value of first combo in to the second combo The second combo...
7
by: C G | last post by:
Dear All, What's the best way to store jpgs in postgresql to use in a web page? I tried to use large objects, but how would you extract them from a table to be viewed in a web-page without...
2
by: WB | last post by:
I have an app that will need to store hostorical data (path & filenames) in a combo box (so that the user doesn't have to type in the same data each time the app is restarted). Is it best to keep...
4
by: dmac | last post by:
Below is some really simple code - its just a trivial class used to populate a combo box from which I want to pull out one of the properties of the selected object. I am just curious to know why -...
1
by: Miesha.James | last post by:
Hello, I'm trying to rewrite visual c++ code into visual c++ .NET code and I've run across a problem with storing objects into a list. Here;s an example of the code I have: ref struct...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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.