Joel Palmer
Top achievements
Rank 2
Joel Palmer
asked on 21 Jul 2010, 12:26 AM
I have a simple 3 column GridView. The 2nd column is defined as a GridViewComboBoxColumn. I would like to bind an Enum list to that ComboBox.ItemsSource property. How do I do this?
On a typical combobox, I could do the following:
On a typical combobox, I could do the following:
cboValueType.ItemsSource = Enum.GetValues(ValueType);
Thanks for your help.
6 Answers, 1 is accepted
0
Ваня
Top achievements
Rank 1
answered on 21 Jul 2010, 05:50 AM
Hello,Joe Palmer
You should make the following modficiation in your code:
You should make the following modficiation in your code:
cboValueType.ItemsSource = Enum.GetValues(typeof(ValueType));
Regards,Vanya
0
Accepted
Hi,
You can also see our online sample. On the right there is an option to bind the combo column to enum.
There is source code available there as well.
Regards,
Pavel Pavlov
the Telerik team
You can also see our online sample. On the right there is an option to bind the combo column to enum.
There is source code available there as well.
Regards,
Pavel Pavlov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Joel Palmer
Top achievements
Rank 2
answered on 21 Jul 2010, 03:30 PM
Yes, you are correct from standpoint of syntax in binding it to a typical combobox. I typed it in from memory so I got it wrong.
However, you failed to answer the question. The question is about how I populate a GridViewComboBoxColumn with these values from an Enum.
Thanks for your help,
Joel
However, you failed to answer the question. The question is about how I populate a GridViewComboBoxColumn with these values from an Enum.
Thanks for your help,
Joel
0
Hello Joel Palmer,
The GridViewComboBoxColumn has its own ItemsSource property which is transfered to the comboboxes. As demonstrated in the sample I pointed out below.
Regards,
Pavel Pavlov
the Telerik team
The GridViewComboBoxColumn has its own ItemsSource property which is transfered to the comboboxes. As demonstrated in the sample I pointed out below.
Regards,
Pavel Pavlov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Joel Palmer
Top achievements
Rank 2
answered on 21 Jul 2010, 03:51 PM
Okay. I got this to work from the example. Evidentially, I need to turn the enum values into a list. Thanks for your help.
List<
SqlCalculator.Library.ValueType
> list =
new List<
SqlCalculator.Library.ValueType
>();
foreach (SqlCalculator.Library.ValueType item in
Enum.GetValues(typeof(SqlCalculator.Library.ValueType)))
{
list.Add(item);
}
valueTypeColumn.ItemsSource = list;
0
Barnabas
Top achievements
Rank 1
answered on 08 Oct 2010, 02:55 PM
I ran across you post while looking for something completely different. The documentation for ItemSource says that it is looking for an IEnumerable. Therefor your initial code example should have worked. The fact that it needed a List<T> instead indicates that it is actually looking for List<T>, IList<T>, or perhaps even IEnumerable<T>. Here is a shorter path.
This will work if ItemSource is looking for IEnumerable<T>. If it is actually looking for List<T> or IList<T> then you would use this.
Hope this helps you or someone else.
valueTypeColumn.ItemsSource = Enum.GetValues(typeof(SqlCalculator.Library.ValueType)).OfType<
SqlCalculator.Library.ValueType
>();
valueTypeColumn.ItemsSource = Enum.GetValues(typeof(SqlCalculator.Library.ValueType)).OfType<
SqlCalculator.Library.ValueType
>().ToList();