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

expando object with properties with special characters

2 Answers 309 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dennis
Top achievements
Rank 1
Dennis asked on 22 Feb 2012, 12:37 PM
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 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 23 Feb 2012, 09:59 AM
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 >>
0
Dennis
Top achievements
Rank 1
answered on 23 Feb 2012, 05:02 PM
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

Tags
GridView
Asked by
Dennis
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Dennis
Top achievements
Rank 1
Share this question
or