This question is locked. New answers and comments are not allowed.
Hi.
I have a simple grid binding a DataTable. The column names in the DataTable are random ints converted to strings and the values are more random ints. If I leave it like that, then a 10x10 DataTable takes 25 seconds to bind and shows no data ... ?
If I prefix the DataTable column names with any character(s) except a digit, then the grid works as expected, bindind and displaying the data in less than a second.
Thoughts ? Thanks -
Scott
I have a simple grid binding a DataTable. The column names in the DataTable are random ints converted to strings and the values are more random ints. If I leave it like that, then a 10x10 DataTable takes 25 seconds to bind and shows no data ... ?
If I prefix the DataTable column names with any character(s) except a digit, then the grid works as expected, bindind and displaying the data in less than a second.
Thoughts ? Thanks -
Scott
<UserControl x:Class="WideGridView.MainPage" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"> <Grid x:Name="LayoutRoot"> <StackPanel> <StackPanel Orientation="Horizontal"> <telerik:RadButton Content="Build Table" Click="RadButton_Build" Width="100" HorizontalAlignment="Left" Background="Wheat"/> <TextBlock Text="Rows:" VerticalAlignment="Center" Margin="5,0,0,0"/> <TextBox Name="NumRows" Width="50" Text="10" Margin="5,0,0,0"/> <TextBlock Text="Columns:" VerticalAlignment="Center" Margin="5,0,0,0"/> <TextBox Name="NumColumns" Width="50" Text="10" Margin="5,0,0,0"/> <TextBlock Text="Column Name Prefix:" VerticalAlignment="Center" Margin="5,0,0,0"/> <TextBox Name="ColumnNamePrefix" Width="50" VerticalAlignment="Center" Margin="5,0,0,0"/> <telerik:RadButton Name="BindButton" Content="Bind to Grid" Background="Wheat" Width="100" IsEnabled="False" Click="RadButton_Bind" Margin="5,0,0,0"/> <TextBlock Name="Message" Margin="5,0,0,0" VerticalAlignment="Center"/> </StackPanel> <telerik:RadGridView Name="myGrid" Width="{Binding ElementName=LayoutRoot, Path=Width}" MaxHeight="500" HorizontalAlignment="Left"/> </StackPanel> </Grid> </UserControl> using System; using System.Collections.Generic; using System.Linq; using System.Windows; using System.Windows.Controls; using Telerik.Data; namespace WideGridView { public partial class MainPage : UserControl { DataTable myTable; DateTime timeThen, timeNow; Random R = new Random(DateTime.Now.Second); public MainPage() { InitializeComponent(); } private void RadButton_Bind(object sender, RoutedEventArgs e) { timeThen = DateTime.Now; myGrid.ItemsSource = myTable; Deployment.Current.Dispatcher.BeginInvoke(() => { timeNow = DateTime.Now; Message.Text = string.Format("Time to set Grid.ItemsSource was: {0}", new TimeSpan(timeNow.Ticks - timeThen.Ticks)); }); BindButton.IsEnabled = false; } private void RadButton_Build(object sender, RoutedEventArgs e) { timeThen = DateTime.Now; int numColumns = Convert.ToInt32(NumColumns.Text); int numRows = Convert.ToInt32(NumRows.Text); List<string> columnNames = new List<string>(); for (int i = 0; i < numColumns; i++) columnNames.Add(string.Format("{0}{1}",ColumnNamePrefix.Text, R.Next().ToString())); if (columnNames.Distinct().Count() != numColumns) MessageBox.Show("Try again."); myTable = new DataTable(); for (int i = 0; i < numColumns; i++) myTable.Columns.Add(new DataColumn() { ColumnName = columnNames[i], DataType = typeof(int) }); for (int i = 0; i < numRows; i++) { DataRow dr = myTable.NewRow(); for (int j = 0; j < numColumns; j++) { dr[columnNames[j]] = R.Next(); } myTable.Rows.Add(dr); } BindButton.IsEnabled = true; Deployment.Current.Dispatcher.BeginInvoke(() => { timeNow = DateTime.Now; Message.Text = string.Format("Time to build table was: {0}", new TimeSpan(timeNow.Ticks - timeThen.Ticks)); }); } } }