473,502 Members | 9,954 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7797
"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
4163
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
4014
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
11359
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
1181
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
9805
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
5528
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
9806
by: Harris | last post by:
Dear all, I have the following codes: ====== public enum Enum_Value { Value0 = 0, Value1 = 10,
3
3621
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
8733
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
7180
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
7059
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...
0
7249
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,...
1
6960
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
5548
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,...
1
4981
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...
0
3153
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...
0
3142
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1481
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 ...

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.