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

Display enum in ComboBox with spaces

Hello,

I have an enum, example:

enum MyEnum
{
My_Value_1,
My_Value_2
}

With :

comboBox1.DataSource = Enum.GetValues(typeof(MyEnum));

I fill the ComboBox Items and with

DataGridViewComboBoxColumn col =
(DataGridViewComboBoxColumn)dataGridView1.Columns[0];
col.DataSource = Enum.GetValues(typeof(EnumNamen));

I can fill a DataBound DataGridViewComboBoxColumn with items.

But now my question: How can I replace the "_" with " " so that I became
items with spaces instead of underscores? And that a databound object still
works

Thanks a lot for your help

Gerrit
Jul 14 '07 #1
1 7783
"Gerrit" <gs*************@hotmail.comwrote in message
news:0U%li.334$Rv4.30@amstwist00...
[...]
enum MyEnum
{
My_Value_1,
My_Value_2
}
[...]
I can fill a DataBound DataGridViewComboBoxColumn with items.

But now my question: How can I replace the "_" with " " so that I became
items with spaces instead of underscores? And that a databound object
still works
You could loop through all the elements, replace the "_", and insert them
into an array, and the databind to your array. For instance, like this:

Array a = Enum.GetValues(typeof(MyEnum));
string[] myValues = new string[a.Length];
for (int i=0; i<a.Length; i++)
{
myValues[i]=a.GetValue(i).ToString().Replace("_"," ");
}

If you are going to do many such conversions, you can experiment a little
bit and do the conversion in a single line by means of Array.ConvertAll(),
providing as an argument a Converter that you write separately to perform
the replacement.

Jul 14 '07 #2

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

Similar topics

14
by: Thelma Lubkin | last post by:
I am trying to limit the user's options to the choices offered by the combobox text, but I don't want this to extend to how he spaces out the text, e.g. 'abcdefg' and 'ab cd efg' should be...
3
by: google | last post by:
This is something I've done plenty of times in '97, but I can't seem to get it to work correctly in Access 2003. Say, for example, I have a form with an unbound combobox, the data source is a...
7
by: gwenda | last post by:
I need a datasource for a third party combobox and the data should come from an enum. I have figured out how to use the enum to create a 2-dimensioned array imitating the form of Key, Value such...
3
by: aburayan | last post by:
Having a SQL table contains many columns. One of them contains integers of corresponding descriptions;i.e 1 for ready, 2 for done .... And i read the values and display the corresponding item list. ...
3
by: Franky | last post by:
does anybody know how to use all values of an enumeration in a combobox? i have an enum type defined like public enum EnumTest { val1 = 1, val2 = 2, val4 = 4, }
4
by: Vish | last post by:
Hi, I need to make the text on a combobox that is disabled to be drawn with a black color. I was not able to find any help on this online. The drawItem seems to apply only for the dropdpwn...
7
by: Harris | last post by:
Dear all, I have the following codes: ====== public enum Enum_Value { Value0 = 0, Value1 = 10,
3
by: Desmond Cassidy | last post by:
I created an Enum with the EnumBuilder which allows you to add items with spaces embedded as well as the name of the Enum. e.g. US States and a member of New York The normal way you would iterate...
11
by: =?Utf-8?B?THVpZ2k=?= | last post by:
Hi all, is it possible to have spaces in enum values? I have an enum like this: public enum Columns { Italy = 1, OtherCountryUE = 2, OtherCountryOCSE = 3, OtherCountr= 4 } and I'd like to...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.