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

2 posts, 0 answers
  1. Marian
    Marian avatar
    1 posts
    Member since:
    Sep 2013

    Posted 11 Sep 2013 Link to this post

    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
     
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 12 Sep 2013 Link to this post

    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 >>
Back to Top