473,698 Members | 2,344 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 3621
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
2614
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
2037
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
4805
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
3042
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
1727
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
3531
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
2330
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
4453
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
9844
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
8609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9169
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9030
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...
0
8871
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...
0
7738
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5861
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
4371
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...
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2007
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.