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

Binding a list to an enumeration...

Hi:

How would I bind a list to an enumeration so that enumeration value becomes
list values and enumeration constants becomes list text? Do you loop
through enum and add manually or is there a way to databind like when using
a table as list backing store?

Thanks,
Charlie
Mar 28 '07 #1
2 3609
Charlie,

Generally, you could cycle through the enumeration and add the items
manually.

If you wanted to take advantage of data binding, then I would create a
generic class like so:

public class EnumListItem<T>
{
public readonly T Value;
public readonly string Display;

public EnumListItem(T value, string display)
{
// Assign the values.
this.Value = value;
this.Display = display;
}
}

Then, you can have a method which will return an IList<EnumListItem>
implementation which you can bind your listbox to. Of course, you set your
DisplayMember to "Display" and your ValueMember to "Value".

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Charlie@CBFC" <ch*****@cbfconsulting.comwrote in message
news:uV**************@TK2MSFTNGP06.phx.gbl...
Hi:

How would I bind a list to an enumeration so that enumeration value
becomes list values and enumeration constants becomes list text? Do you
loop through enum and add manually or is there a way to databind like when
using a table as list backing store?

Thanks,
Charlie

Mar 28 '07 #2
Interesting. Thanks!
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:es**************@TK2MSFTNGP05.phx.gbl...
Charlie,

Generally, you could cycle through the enumeration and add the items
manually.

If you wanted to take advantage of data binding, then I would create a
generic class like so:

public class EnumListItem<T>
{
public readonly T Value;
public readonly string Display;

public EnumListItem(T value, string display)
{
// Assign the values.
this.Value = value;
this.Display = display;
}
}

Then, you can have a method which will return an IList<EnumListItem>
implementation which you can bind your listbox to. Of course, you set
your DisplayMember to "Display" and your ValueMember to "Value".

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Charlie@CBFC" <ch*****@cbfconsulting.comwrote in message
news:uV**************@TK2MSFTNGP06.phx.gbl...
>Hi:

How would I bind a list to an enumeration so that enumeration value
becomes list values and enumeration constants becomes list text? Do you
loop through enum and add manually or is there a way to databind like
when using a table as list backing store?

Thanks,
Charlie


Mar 29 '07 #3

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

Similar topics

42
by: Alan McIntyre | last post by:
Hi all, I have a list of items that has contiguous repetitions of values, but the number and location of the repetitions is not important, so I just need to strip them out. For example, if my...
1
by: Andy Wells | last post by:
I'm using VB.NET and I have an application that binds a schema to the main form's controls, and the user has the ability to load an XML file through the schema and into the bound form. My...
1
by: Max | last post by:
Suppose I have a simple type which is enumeration <xs:simpleType name="fontStyle"> <xs:restriction base="xs:string"> <xs:enumeration value="bold" /> <xs:enumeration value="italic" />...
3
by: TN | last post by:
I have a list like this defined in my wsdl: <xsd:simpleType name="MyPets"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="dog"/> <xsd:enumeration value="cat"/> <xsd:enumeration...
2
by: mark | last post by:
I understand that writing programs with option strict on is the best way to obtain stable applications. I have also found the applications to run much faster. Option strict on disallows late...
0
by: mancha28 | last post by:
Hi, I have create Word object by late binding to open a Word document and save it under another name. This new saved document should be saved as mht-file. Following code I impelemented: ...
0
by: Steven Bolard | last post by:
Hello, I am trying to port my .net 1.1 application to 2.0. I am using vs2005. I am trying to get my webservices to run and although i can compile them and and get wsdl and service descriptions...
7
by: Nathan | last post by:
I'd like to use an enumeration as a datasource for a drop-down box. Is there a way to do this?
6
by: kimiraikkonen | last post by:
Hello, I've been working on a project and i wonder how to get list of the LAN computer names in a tree list which are involved under the same workgroup name? What can be the code be? Very...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.