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

Silverilght DataTable

1 Answer 61 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Harish
Top achievements
Rank 1
Harish asked on 27 Oct 2010, 07:53 PM
Hi,

I am currently using a DataTable that Vlad had developed to bind the data to my grid. In the code I observed that we have
var firstItem = source.FirstOrDefault();
With this we identify the column and it datatype before we add to the column list. This works fine as long as the first row has no null values. But what if one of the row values is null? Its failing to identify the Type of the column and therefore fails to bind the data. Any solution to this issue?

Harish

1 Answer, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 02 Nov 2010, 10:16 AM
Hello Harish,

 You can create the grid columns (instead auto-generated columns) based on DataTable columns:

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) });
 
table.Columns.Add(new DataColumn() { ColumnName = "CustomType", DataType = typeof(MyCustomType) });
 
RadGridView1.AutoGenerateColumns = false;
 
foreach (var c in table.Columns)
{
    RadGridView1.Columns.Add(new GridViewDataColumn()
    {
        DataMemberBinding = new System.Windows.Data.Binding(c.ColumnName),
        Header = c.ColumnName,
        DataType = c.DataType
    });
}
 
RadGridView1.ItemsSource = table;


Sincerely yours,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Harish
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or