472,951 Members | 1,855 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Name Value pair in Combolist

RSH

I need to use a form element to display a list of users. I would like to
store their ID "behind the scenes" so when the user selects a name the Event
passes their ID.

I can't find anything about how to set a Name/Value pair of a ComboList. Is
this the wrong tool for the job? Or how do I set the two values?

Thanks so much,
Ron
Jan 10 '06 #1
7 2530
KJ
I'm not sure if this is built-in to the existing control or note, but I
do know that you can inherit from System.Windows.Forms.ComboBox, and
add your own internal list to store values.

Jan 10 '06 #2
ComboList? do you mean ListBox?

Anyway... the easiest option is to:

write a class (if you haven't already) that does:

public class User {
public int ID; // yes, cheaky, but quick for demo
public string Name; // likewise
public override string ToString() {
return Name;
}
}

Now, instead of adding the strings, create User objects and add those; when
displaying the system will use the ToString() as the display text. When you
call SelectedValue, just cast back to a User and grab the ID (or whatever).

There's probably a dozen other ways, but that works - as long as you don't
allow free text input.

Also - why not pass the User object to the event and let the subscriber
worry about what they want to use?

Marc

"RSH" <wa*************@yahoo.com> wrote in message
news:OY**************@TK2MSFTNGP09.phx.gbl...

I need to use a form element to display a list of users. I would like to
store their ID "behind the scenes" so when the user selects a name the
Event passes their ID.

I can't find anything about how to set a Name/Value pair of a ComboList.
Is this the wrong tool for the job? Or how do I set the two values?

Thanks so much,
Ron

Jan 10 '06 #3
Sory - I meant ComboBox... I think... But the principle stands...

(time for more coffee)

Marc

"Marc Gravell" <mg******@rm.com> wrote in message
news:e9**************@TK2MSFTNGP15.phx.gbl...
ComboList? do you mean ListBox?

Anyway... the easiest option is to:

write a class (if you haven't already) that does:

public class User {
public int ID; // yes, cheaky, but quick for demo
public string Name; // likewise
public override string ToString() {
return Name;
}
}

Now, instead of adding the strings, create User objects and add those;
when displaying the system will use the ToString() as the display text.
When you call SelectedValue, just cast back to a User and grab the ID (or
whatever).

There's probably a dozen other ways, but that works - as long as you don't
allow free text input.

Also - why not pass the User object to the event and let the subscriber
worry about what they want to use?

Marc

"RSH" <wa*************@yahoo.com> wrote in message
news:OY**************@TK2MSFTNGP09.phx.gbl...

I need to use a form element to display a list of users. I would like to
store their ID "behind the scenes" so when the user selects a name the
Event passes their ID.

I can't find anything about how to set a Name/Value pair of a ComboList.
Is this the wrong tool for the job? Or how do I set the two values?

Thanks so much,
Ron


Jan 10 '06 #4
RSH
I'm having a little problem conceptualizing this...

Here is what I have so far:

public void FillEmployees(DataSet DS, ComboBox ComboList)

{

if (bAuthenticated == true)

{

foreach (DataRow DR in DS.Tables[0].Rows)

{

String sTemp = DR["ID"].ToString().PadLeft(8, '0');

Employee emp = new Employee(); <--------------- How do I create each object
name so it can be referenced later?

emp.FirstName = DR["FirstName"].ToString();

emp.LastName = DR["LastName"].ToString();

emp.ID = sTemp;

ComboList.Items.Add(emp.ToString());
}

}

}

}

class Employee

{

private String iD;

private String firstName;

private String lastName;

public string ID

{

get { return iD; }

set { iD = value; }

}

public string FirstName

{

get { return firstName; }

set { firstName = value; }

}

public string LastName

{

get { return lastName; }

set { lastName = value; }

}

public override string ToString()

{

return ID;

}

}

}










"Marc Gravell" <mg******@rm.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
Sory - I meant ComboBox... I think... But the principle stands...

(time for more coffee)

Marc

"Marc Gravell" <mg******@rm.com> wrote in message
news:e9**************@TK2MSFTNGP15.phx.gbl...
ComboList? do you mean ListBox?

Anyway... the easiest option is to:

write a class (if you haven't already) that does:

public class User {
public int ID; // yes, cheaky, but quick for demo
public string Name; // likewise
public override string ToString() {
return Name;
}
}

Now, instead of adding the strings, create User objects and add those;
when displaying the system will use the ToString() as the display text.
When you call SelectedValue, just cast back to a User and grab the ID (or
whatever).

There's probably a dozen other ways, but that works - as long as you
don't allow free text input.

Also - why not pass the User object to the event and let the subscriber
worry about what they want to use?

Marc

"RSH" <wa*************@yahoo.com> wrote in message
news:OY**************@TK2MSFTNGP09.phx.gbl...

I need to use a form element to display a list of users. I would like
to store their ID "behind the scenes" so when the user selects a name
the Event passes their ID.

I can't find anything about how to set a Name/Value pair of a ComboList.
Is this the wrong tool for the job? Or how do I set the two values?

Thanks so much,
Ron



Jan 10 '06 #5
And I meant SelectedItem... <cringes at own ineptitude this evening>

You may also be able to use SelectedValue with binding to the object type,
but that might be more work.

Marc

"Marc Gravell" <mg******@rm.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
Sory - I meant ComboBox... I think... But the principle stands...

(time for more coffee)

Marc

"Marc Gravell" <mg******@rm.com> wrote in message
news:e9**************@TK2MSFTNGP15.phx.gbl...
ComboList? do you mean ListBox?

Anyway... the easiest option is to:

write a class (if you haven't already) that does:

public class User {
public int ID; // yes, cheaky, but quick for demo
public string Name; // likewise
public override string ToString() {
return Name;
}
}

Now, instead of adding the strings, create User objects and add those;
when displaying the system will use the ToString() as the display text.
When you call SelectedValue, just cast back to a User and grab the ID (or
whatever).

There's probably a dozen other ways, but that works - as long as you
don't allow free text input.

Also - why not pass the User object to the event and let the subscriber
worry about what they want to use?

Marc

"RSH" <wa*************@yahoo.com> wrote in message
news:OY**************@TK2MSFTNGP09.phx.gbl...

I need to use a form element to display a list of users. I would like
to store their ID "behind the scenes" so when the user selects a name
the Event passes their ID.

I can't find anything about how to set a Name/Value pair of a ComboList.
Is this the wrong tool for the job? Or how do I set the two values?

Thanks so much,
Ron



Jan 10 '06 #6
Aah... you never mentioned datasets...

Code to explain my messed-up witterings:

public partial class Form2 : Form {
public Form2() {
InitializeComponent();
comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
comboBox1.Items.Clear();
comboBox1.Items.Add(new User("Frodo", 20));
comboBox1.Items.Add(new User("Samwise", 40));
comboBox1.Items.Add(new User("Medideth", 60));
comboBox1.SelectedIndexChanged += new
EventHandler(comboBox1_SelectedIndexChanged);
}

void comboBox1_SelectedIndexChanged(object sender, EventArgs e) {
MessageBox.Show(((User)comboBox1.SelectedItem).ID. ToString());
}
public class User {
public int ID; // yes, cheaky, but quick for demo
public string Name; // likewise
public override string ToString() {
return Name;
}
public User(string name, int id) {
ID = id;
Name = name;
}
}
}
===================

Anyway, if you are using datasets you should be able to bind directly to the
columns, and just bind the ValueMember to be "ID" and use SelectedValue...?

I can't personally give examples to this as (due to the systems I tend to
work on) I don't tend to use datasets at the UI - but MSDN2 is your friend.

Marc
"RSH" <wa*************@yahoo.com> wrote in message
news:um**************@TK2MSFTNGP11.phx.gbl...
I'm having a little problem conceptualizing this...

Here is what I have so far:

public void FillEmployees(DataSet DS, ComboBox ComboList)

{

if (bAuthenticated == true)

{

foreach (DataRow DR in DS.Tables[0].Rows)

{

String sTemp = DR["ID"].ToString().PadLeft(8, '0');

Employee emp = new Employee(); <--------------- How do I create each
object name so it can be referenced later?

emp.FirstName = DR["FirstName"].ToString();

emp.LastName = DR["LastName"].ToString();

emp.ID = sTemp;

ComboList.Items.Add(emp.ToString());
}

}

}

}

class Employee

{

private String iD;

private String firstName;

private String lastName;

public string ID

{

get { return iD; }

set { iD = value; }

}

public string FirstName

{

get { return firstName; }

set { firstName = value; }

}

public string LastName

{

get { return lastName; }

set { lastName = value; }

}

public override string ToString()

{

return ID;

}

}

}










"Marc Gravell" <mg******@rm.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
Sory - I meant ComboBox... I think... But the principle stands...

(time for more coffee)

Marc

"Marc Gravell" <mg******@rm.com> wrote in message
news:e9**************@TK2MSFTNGP15.phx.gbl...
ComboList? do you mean ListBox?

Anyway... the easiest option is to:

write a class (if you haven't already) that does:

public class User {
public int ID; // yes, cheaky, but quick for demo
public string Name; // likewise
public override string ToString() {
return Name;
}
}

Now, instead of adding the strings, create User objects and add those;
when displaying the system will use the ToString() as the display text.
When you call SelectedValue, just cast back to a User and grab the ID
(or whatever).

There's probably a dozen other ways, but that works - as long as you
don't allow free text input.

Also - why not pass the User object to the event and let the subscriber
worry about what they want to use?

Marc

"RSH" <wa*************@yahoo.com> wrote in message
news:OY**************@TK2MSFTNGP09.phx.gbl...

I need to use a form element to display a list of users. I would like
to store their ID "behind the scenes" so when the user selects a name
the Event passes their ID.

I can't find anything about how to set a Name/Value pair of a
ComboList. Is this the wrong tool for the job? Or how do I set the two
values?

Thanks so much,
Ron



Jan 10 '06 #7
RSH

That definitely worked...now I just need to try and understand what the hell
you built! :-)
Thanks for your help!!!

Ron
"Marc Gravell" <mg******@rm.com> wrote in message
news:Ov**************@TK2MSFTNGP15.phx.gbl...
And I meant SelectedItem... <cringes at own ineptitude this evening>

You may also be able to use SelectedValue with binding to the object type,
but that might be more work.

Marc

"Marc Gravell" <mg******@rm.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
Sory - I meant ComboBox... I think... But the principle stands...

(time for more coffee)

Marc

"Marc Gravell" <mg******@rm.com> wrote in message
news:e9**************@TK2MSFTNGP15.phx.gbl...
ComboList? do you mean ListBox?

Anyway... the easiest option is to:

write a class (if you haven't already) that does:

public class User {
public int ID; // yes, cheaky, but quick for demo
public string Name; // likewise
public override string ToString() {
return Name;
}
}

Now, instead of adding the strings, create User objects and add those;
when displaying the system will use the ToString() as the display text.
When you call SelectedValue, just cast back to a User and grab the ID
(or whatever).

There's probably a dozen other ways, but that works - as long as you
don't allow free text input.

Also - why not pass the User object to the event and let the subscriber
worry about what they want to use?

Marc

"RSH" <wa*************@yahoo.com> wrote in message
news:OY**************@TK2MSFTNGP09.phx.gbl...

I need to use a form element to display a list of users. I would like
to store their ID "behind the scenes" so when the user selects a name
the Event passes their ID.

I can't find anything about how to set a Name/Value pair of a
ComboList. Is this the wrong tool for the job? Or how do I set the two
values?

Thanks so much,
Ron



Jan 10 '06 #8

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

Similar topics

3
by: Ruaidhri | last post by:
I want to store many different types of objects in a single table. I was thinking of using the name value pair approach to achieve this. Does anybody have any experience with a such a design? ...
2
by: Astra | last post by:
Hi everybody Need your help. I have a DB-extracted list of say 5 items per page, which have links on each one that takes you to more detailed info on the 'clicked' particular item. When you...
5
by: brettr | last post by:
When I reference document.cookie, there is a long string of key=value; pairs listed. I may have 100 hundred cookies on my hard drive. However, most only have one key=value pair. Does the...
7
by: Jim Adamson | last post by:
I have created a web page that receives names and values from a URL string of another page e.g. http://hostname/resolve?sublibrary=JMLibrary&collection=Elton&shelfmark=LM 36TY ... and decodes the...
1
by: jadamson60 | last post by:
>From http://developer.irt.org/script/992.htm ============================================= Q992 How can I accept a name/value pair in the current url and access it as a variable and value? ...
16
by: Bush is a Fascist | last post by:
Hi all, What do most languages call a name-value pairing? Or perhaps my question should be, why not just call it a name-value pairing? Too many syllables? Did Knuth invent a handy term for...
0
by: David Lozzi | last post by:
Howdy, I'm trying to get the values from a string of name/value pairs. I'm using a RegEx (I'm very new to RegEx) expression as seen below Dim regExp As Regex Dim m As Match m =...
2
by: Kevin Blount | last post by:
I have an issue with trying to add a new name-pair to an existing cookie. Here's what I want to do: page1 - adds "loggedin=true" to cookie "Communities" adds "member_id=100" to cookie...
2
by: Andrus | last post by:
I'm trying to compile myGeneration PropertyCollectionAll.cs file with VCS Express 2005 bot got error Error 1 The type or namespace name 'Collection' could not be found (are you missing a using...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.