473,729 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3625
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<EnumListI tem>
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.co m

"Charlie@CB FC" <ch*****@cbfcon sulting.comwrot e in message
news:uV******** ******@TK2MSFTN GP06.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.c omwrote in
message news:es******** ******@TK2MSFTN GP05.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<EnumListI tem>
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.co m

"Charlie@CB FC" <ch*****@cbfcon sulting.comwrot e in message
news:uV******** ******@TK2MSFTN GP06.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
2616
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 original list is , I want to end up with . Here is the way I'm doing this now: def straightforward_collapse(myList):
1
2039
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 problem is this: the schema contains an element called "TRENDED" and it has an attribute called "type" whose value can be "previous" or "current". This element can occur twice in the XML, once with the attribute-value "previous" and a second time with...
1
4811
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" /> <xs:enumeration value="underlined" /> <xs:enumeration value="strikeout" /> </xs:restriction> </xs:simpleType>
3
3045
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 value="fish"/> </xsd:restriction> </xsd:simpleType>
2
1731
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 binding, so if I have an array with class level scope and I am operating on that array at procedure level I fabricate a "dummy array" and copy the class level array into it. Then after performing the task I can copy the "dummy array" back into the...
0
3532
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: Parameters = new object; Parameters = "fileName.mht"; Parameters = WdSaveFormat.wdFormatWebArchive; Parameters = false;
0
2344
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 through internet explorer when hitting the ..asmx url, i cannot generate a proxy class to use in my winforms assembly. When i try to generate a proxy, i get no error message but nor do i get a reference.vb so there is no type info. If i then try...
7
4456
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
9845
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 thanks.
0
8925
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9288
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9206
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9154
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6722
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6026
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4531
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2692
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2166
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.