Telerik blogs

 

UPDATE: Please visit this post for more info about dynamic objects binding!

 

Since there is no DataTable in Silverlight I’ve created small class that can be used to generate columns and rows in runtime in similar to the real DataTable way:

DataTable table = new DataTable();

table.Columns.Add(new DataColumn() { ColumnName = "ID", DataType = typeof(int) });
table.Columns.Add(new DataColumn() { ColumnName = "Name", DataType = typeof(string) });
table.Columns.Add(new DataColumn() { ColumnName = "UnitPrice", DataType = typeof(decimal) });
table.Columns.Add(new DataColumn() { ColumnName = "Date", DataType = typeof(DateTime) });
table.Columns.Add(new DataColumn() { ColumnName = "Discontinued", DataType = typeof(bool) });

for(var i = 0; i < 1000; i++)
{
DataRow row = new DataRow();
row["ID"] = i;
row["Name"] = names[rnd.Next(9)];
row["UnitPrice"] = prizes[rnd.Next(9)];
row["Date"] = DateTime.Now.AddDays(i);
row["Discontinued"] = bools[rnd.Next(9)];

table.Rows.Add(row);
}

 

Enjoy!


About the Author

Vladimir Enchev

is Director of Engineering, Native Mobile UI & Frameworks

Comments

Comments are disabled in preview mode.