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

[Solved] Grid behaves oddly when column names are stringed ints ...

3 Answers 47 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
scott
Top achievements
Rank 1
scott asked on 01 Oct 2010, 04:31 PM
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

<UserControl x:Class="WideGridView.MainPage"
    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));
                });
        }
    }
}

3 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 06 Oct 2010, 01:30 PM
Hi scott,

Can you please check  the VS output window for binding expression errors while running the app ?

All the best,
Pavel Pavlov
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
0
scott
Top achievements
Rank 1
answered on 06 Oct 2010, 03:17 PM
Hi Pavel - nothing unusual in the debug window.  My comlpete code is in the original post and may help you reproduce the issue - the workaround is simple so its a non issue for me.  Just thought you guys might want to know about it...

Regards -
Scott

0
Pavel Pavlov
Telerik team
answered on 11 Oct 2010, 04:33 PM
Hello scott,

Unfortunately nothing can be done  to improve the situation. Internally the SL datatable tries to create dynamic properties with the names given for the columns.  The conflict is propertyname <-> numbers only string  which interferes with the binding mechanisms.  

As a workaround I may suggest to use prefixed properties , and display them in the headers without the prefixes ( e.g. using the Header property of the column) .

Best wishes,
Pavel Pavlov
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
GridView
Asked by
scott
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
scott
Top achievements
Rank 1
Share this question
or