473,385 Members | 1,356 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,385 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 7790
"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...
1
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.