473,398 Members | 2,165 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.

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 7791
"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: 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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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.