expando object with properties with special characters

3 posts, 0 answers
  1. Dennis
    Dennis avatar
    4 posts
    Member since:
    Aug 2012

    Posted 22 Feb 2012 Link to this post

    Hi,

    We are busy developing a silverlight app that has to show some data in tabular form. The radgridview to be able to visualize random data. We want to use MVVM pattern.

    Our solution is to format th input data into an observable collection of expando objects

    we do that like this

     

     

    private void CreateDataSourceList(ChartInfo results)

     

    {

     

     

    List<List<object>> theRows = results.TableData.Rows;

     

     

     

    var titles = results.TableData.ColumnTitles.Keys.ToList();

     

    TheListOfitems =

     

    new ObservableCollection<dynamic>();

     

     

     

    foreach (var rowItem in theRows)

     

    {

     

     

    dynamic expando = new ExpandoObject();

     

     

     

    int counter = 0;

     

     

     

    foreach (var columnName in titles)

     

    {

     

     

    // var columnNameFixed = System.Windows.Browser.HttpUtility.HtmlEncode(columnName);

     

     

     

    var columnNameFixed = FixUpColumnName(columnName);

     

     

     

    var p = expando as IDictionary<String, object>;

     

     

     

    var columnString = rowItem[counter] as ColumnString;

     

     

     

    if (columnString != null)

     

    {

    p[columnNameFixed] = columnString.ToString();

    }

     

     

    else

     

    {

     

     

    var columnDouble = rowItem[counter] as ColumnDouble;

     

     

     

    if (columnDouble != null)

     

    {

    p[columnNameFixed] = columnDouble;

    }

     

     

    else

     

    {

    p[columnNameFixed] =

     

    string.Empty;

     

    }

    }

    counter++;

    }

    TheListOfitems.Add(expando);

    }

    }

    WE hook up this observable collection (TheListOfitems) to radgridview in xaml like this.

     

     

     

     

    <telerik:RadGridView x:Name="datagrid" Grid.Row="1" AutoGenerateColumns="True" IsReadOnly="True" ItemsSource="{Binding TheListOfitems}"

     

     

     

    MaxColumnWidth="250" >

     

     

     

     

    </telerik:RadGridView>

     

     

     

     

    Note the autogeneratecolumns property. This works like a charm!

    The problem is however the need for the function FixUpColumnName, we need this for the columnnames can contain strings like "abc(123>)", and these will

    Not applying the function FixUpColumnName results in a bug (?): the radgridview will generate the column correctly, but the rows are empty. they are not filled with the corresponding data.

    FixUpColumnName is a function that now will replace every strange character with a underscore like this

     

    private

     

     

    static string FixUpColumnName(string columnName)

     

    {

     

     

    Regex re = new Regex("[^ a-zA-Z0-9\n]");

     

     

     

    return re.Replace(columnName,"_");

     

    }

     

     

    Our users however do want the original columnname to be displayed.

    How can this be solved?
    Is there some sort of escaping possible?

    Kind Regards

    Dennis Janssen
    PRe Consultants
    NEtherlands







  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 23 Feb 2012 Link to this post

    Hello,

     Why not use the original column name for the grid column headers only? I'm afraid that we will unable to provide support for such scenario. 

    Regards,
    Vlad
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. Dennis
    Dennis avatar
    4 posts
    Member since:
    Aug 2012

    Posted 23 Feb 2012 Link to this post

    thx for the reply,
    I think I have solved it like you said. For that I had to implement the RadGridViewHelper (see http://www.telerik.com/community/forums/silverlight/gridview/radgridview-columns-binding-mvvm.aspx)

    In that way I can control the uniquename and displayname seperately.

    so my problem is solved

Back to Top