Objects and list boxes
-
I am getting data from a database, and after some pushing and poking, I have a User object. I then create a list of these Users. I have a couple of accessors:
public string FullName()
{
get
{
return m_name;
}
}public User GetUser()
{
get
{
return this;
}
}and
lstUsers.DisplayMember = "FullName";
lstUsers.ValueMember = "GetUser";and finally
private void lstUsers_SelectedIndexChanged(...)
{
User u = (User)(lstUsers.SelectedValue);
...
}There must be an easy way than this. Any ideas? Regards, Barry
-
I am getting data from a database, and after some pushing and poking, I have a User object. I then create a list of these Users. I have a couple of accessors:
public string FullName()
{
get
{
return m_name;
}
}public User GetUser()
{
get
{
return this;
}
}and
lstUsers.DisplayMember = "FullName";
lstUsers.ValueMember = "GetUser";and finally
private void lstUsers_SelectedIndexChanged(...)
{
User u = (User)(lstUsers.SelectedValue);
...
}There must be an easy way than this. Any ideas? Regards, Barry
Barry Lapthorn wrote: There must be an easy way than this. Any ideas? Looks easy enough for me! top secret xacc-ide 0.0.1
-
Barry Lapthorn wrote: There must be an easy way than this. Any ideas? Looks easy enough for me! top secret xacc-ide 0.0.1
I should have said 'less crap' ;) The 'callback' is a string. Seems to me like it would be boiler plate code (returning an object handle from a selected list) and perhaps should have been in the CLR. Regards, Barry
-
I am getting data from a database, and after some pushing and poking, I have a User object. I then create a list of these Users. I have a couple of accessors:
public string FullName()
{
get
{
return m_name;
}
}public User GetUser()
{
get
{
return this;
}
}and
lstUsers.DisplayMember = "FullName";
lstUsers.ValueMember = "GetUser";and finally
private void lstUsers_SelectedIndexChanged(...)
{
User u = (User)(lstUsers.SelectedValue);
...
}There must be an easy way than this. Any ideas? Regards, Barry
Barry Lapthorn wrote: There must be an easy way than this. Any ideas? To do what? You really haven't said what your problem is. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
Barry Lapthorn wrote: There must be an easy way than this. Any ideas? To do what? You really haven't said what your problem is. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
You could also override the ToString() method of your object and make it return the username as a string. As far as the callback goes, why not just insert the object into the listbox. When you want to get it back out, all you need to do is cast it to the appropriate type. Or am I missing something? Will
-
Barry Lapthorn wrote: There must be an easy way than this. Any ideas? To do what? You really haven't said what your problem is. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
My problem is that return the reference to the object from a drop down list must be a common thing, and there's no consistent (e.g. interface) way of doing it, and that the way you have to do it is via a function call back that is a string, and therefore weakly typed. Regards, Barry
-
You could also override the ToString() method of your object and make it return the username as a string. As far as the callback goes, why not just insert the object into the listbox. When you want to get it back out, all you need to do is cast it to the appropriate type. Or am I missing something? Will
Do you have an example of this? :) Regards, Barry