This is a migrated thread and some comments may be shown as answers.

Autogenerated columns in a RadGridView should show an enum type as a ComboBox

1 Answer 182 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Marian
Top achievements
Rank 1
Marian asked on 11 Sep 2013, 08:17 AM

Hello,

I‘d like to show  xml data (with xsd) in a RadGridView and edit its value. The values in the grid should allow only this data, which are allowed in xsd. For instance, for enum type I would like to have a ComboBox column.

 

In Xaml I have a following code:

 

<telerik:RadGridView x:Name="dataGrid" AutoGenerateColumns="True" CanUserResizeRows="True"> 
</telerik:RadGridView>
 
The xml data is loaded in a DataSet and connected to the grid:
 
private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            var data = new DataSet();
            data.ReadXmlSchema(@"D:\Development\Data\IBISConfig.xsd");
            data.ReadXml(@"D:\Development\Data\IBISConfig.xml");
 
            dataGrid.DataMember = data.Tables[data.Tables.Count - 1].TableName;
            dataGrid.ItemsSource = data;
        }
 
 
The Xml file is shown as a hierachical data, but the data types in the columns are always strings. 
 
How can I change the column type, without to parse the xsd?

Best Regards
Marian
 

1 Answer, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 12 Sep 2013, 11:59 AM
Hi,

In order to replace the default editor for enum types and use a ComboBox instead, you should subscribe for the AutoGeneratingColumn event. Once it is raised for the column bound to the enum values, you can set any CellEditTemplate you wish.

private void grid_AutoGeneratingColumn_1(object sender, GridViewAutoGeneratingColumnEventArgs e)         
{
...
e.Column.CellEditTemplate =
this.Resources["ComboEditTemplate"] as DataTemplate;
}

I hope this helps.

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Marian
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Share this question
or