none
DataGrid Bugs

    Question

  • I have found several DataGrid non-fatal UI bugs:

    1) There are 2 horizontal lines at top of the DataGrid container when the grid is empty. They just look weird.

    2) When setting HeadersVisibility="Column" in the XAML, the header cells and the data cells down below are not aligned. The header has some offset to the right.  The strange thing is when I set the HeadersVisibility=DataGridHeaders.Column in code, it works fine.

    3) If I have many columns in the DataGrid,  when I scroll to right to see all the columns, sometimes the data row are broken in the middle. The Header row is extending to all the way to the right, but data rows are stopped in the middle, not extending all the way to the right until I try to resize a column. When I try to resize a column, everything is back to normal.

     

     


    Tuesday, June 17, 2008 11:14 AM

All replies

  • I have a problem where I populate the datagrid, then select a cell for editing, then scroll up and down, and the datagrid fatally crashes.

    Friday, June 20, 2008 1:16 AM
  • I have seen fatal crashes of the Silverlight plugin with the datagrid. For example when I sort a column and before it is finished I start a couple of other sort actions by clicking column headers. The DataGrid is surely not at beta level yet.

    Rick

    Friday, June 20, 2008 10:34 AM
  •  Found more problems with DataGrid:

    1) FrozenColumnCount is not working at all. It does nothing. It should freeze the first 2 columns if I set it to FrozenColumnCount = 2. But it does not.

    2) CanUserReorderColumns not working with custom header. Only works with default header.

    In beta 2 DataGrid got several new settings. One of them is CanUserReorderColumns setting. If do not use any custom header, just set the column.Header = "MyHeaderText".  This feature works fine. I can drag the column header and re-order them.

    The default header is not center aligned.  So I need custom header. I create my column header in code:

                   foreach (DataGridColumn col in theGrid.Columns)
                    {
                       Grid g = new Grid();                  
                        TextBlock txt = new TextBlock();
                        txt.Margin = new Thickness(5, 5, 5, 5);
                        txt.Text = col.Header;
                        txt.HorizontalAlignment = HorizontalAlignment.Center;
                        txt.VerticalAlignment = VerticalAlignment.Center;             
                        g.Children.Add(txt);
                        col.Header = g;                  
                    }

    The problem is when I create custom header, I can no longer re-order the columns. When I tried to drag the header I would get "Value does not fall within expected range" error. If I do not catch this error, it crashes.

     

     

     

     

    Friday, June 20, 2008 11:51 AM
  • This isn't a bug, but does anyone else notice that when you click to sort the grid, it's VERY slow?

    Sam...

     

    Saturday, June 21, 2008 1:33 AM
  • Sorting is indeed very slow especially the first time. I have a 30x30 grid and it can take a couple of seconds for sorting. That's why (since there is no hourglass) I can accidently start multi sort operations and get Silverlight plugin to crash.

    Saturday, June 21, 2008 3:28 AM
  • This isn't a bug, but does anyone else notice that when you click to sort the grid, it's VERY slow?

     

    Yes, I've noticed that too.

     

    Saturday, June 21, 2008 9:20 AM
  • Found another one:

    DataGrid.SelectedIndex is always -1 no matter which row is selected.

    Monday, June 23, 2008 11:11 AM
  •  Another one:

    When clicking column header to sort, sometimes the whole grid (every row) become highlighted (like they are selected).

    Friday, June 27, 2008 12:18 PM
  •  I found that sometimes if you have lets say 50 items in the datagrid source and have to scroll to see all of the items, the datagrid scroller will stop before you get to see all of the items. If there are 50 total items sometimes I will get to like 47/48 and it will be at the very bottom of the scroller. Sometimes you can see part of 49 or 50 and if you click on it, it seems to fix the datagrid.

     Clicking the scroll bar on the right seems to make this happen more often than the up/down arrows for scrolling.

     -Eric
    Friday, June 27, 2008 12:51 PM
  • Sorting is in fact broken in SL2B2, resulting in fatal crashes when you try to sort a column that had a binding failure.

     


         public partial class Page : UserControl
        {
            public Page()
            {
                InitializeComponent();

                dataGrid5.ItemsSource = Person.GetSamplePersonList();
            }
        }

     

        public class Person
        {
            public Int32 Person_pk { get; set; }
            public String FirstName { get; set; }
            public String LastName { get; set; }

            //commented out to simulate binding failure
            //public String Address { get; set; }

            public Person()
            {
            }

            public static List<Person> GetSamplePersonList()
            {
                return new List<Person> {
                    new Person {Person_pk = 0, FirstName = "A.", LastName = "Zero"},
                    new Person {Person_pk = 1, FirstName = "B.", LastName = "One"},
                    new Person {Person_pk = 2, FirstName = "C.", LastName = "Two"},
                    new Person {Person_pk = 3, FirstName = "D.", LastName = "Three"}
                };
            }
        }

     

     <UserControl x:Class="Page"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data">
        <StackPanel x:Name="LayoutRoot">
            <TextBlock Text="DataGrid Demonstration"
                       Margin="0,20,10,20"
                       FontFamily="Verdana" FontSize="18" FontWeight="Bold"
                       Foreground="#FF5C9AC9" />
            <Rectangle Fill="AliceBlue" HorizontalAlignment="Stretch" Height="1"/>
     
            
            <TextBlock Text="DataGrid with template column:"/>
            <data:DataGrid x:Name="dataGrid5"
                           Height="120"
                           Margin="0,5,0,10"  HorizontalAlignment="Left"
                           AutoGenerateColumns="False">            
            <data:DataGrid.Columns>
                
                <data:DataGridTemplateColumn>
                <data:DataGridTemplateColumn.Header>
                    <TextBlock Text="Name"/>
                </data:DataGridTemplateColumn.Header>
                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Padding="5,0,5,0"
                                       Text="{Binding FirstName}"/>
                            <TextBlock Text="{Binding LastName}"/>
                        </StackPanel>
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
                <data:DataGridTemplateColumn.CellEditingTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <TextBox Padding="5,0,5,0"
                                     Text="{Binding FirstName}"/>
                            <TextBox Text="{Binding LastName}"/>
                        </StackPanel>
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellEditingTemplate>
                </data:DataGridTemplateColumn>   
                

    <!-- databinding to a column whose displaymemberbinding doesn't exist causes entire silverlight app to fail -->
                <data:DataGridTextColumn Header="Address"
                                         Width="300"
                                         DisplayMemberBinding="{Binding Address}" />
            </data:DataGrid.Columns>
            </data:DataGrid>
        </StackPanel>
    </UserControl>

    Tuesday, July 01, 2008 3:48 PM
  •  Also, another bug in DataGrid:

     Adding a DataGridTemplateColumn without a body is undefined, and fatally crashes the application:

     
    In the above data grid code snippet, add:

    <DataGridTemplateColumn/>

    to the columns collection.
     

    Tuesday, July 01, 2008 4:57 PM
  • Not necessarily a bug, but a feature so basic it should be a bug:

     DataGrid has no public refresh/update method so if you add items to a List that is being used as the ItemsSource, the DataGrid will not display the new items until you attempt to sort a column or point the ItemsSource at some other object (like null) then back to the List that you just added to.

    Tuesday, July 01, 2008 7:25 PM
  • Not necessarily a bug, but a feature so basic it should be a bug:

     DataGrid has no public refresh/update method so if you add items to a List that is being used as the ItemsSource, the DataGrid will not display the new items until you attempt to sort a column or point the ItemsSource at some other object (like null) then back to the List that you just added to.

     

    Hi,  You can use ObservableCollection<DataObject> instead of List<DataObject> to hold your data. Then you should see the DataGrid or ListBox reflect that change automatically when you add item to the list or delete it from the list.

     

     

    Tuesday, July 01, 2008 8:41 PM
  •  And to update your cell on every object update, your object must implement : INotifyPropertyChanged.

     

    Monday, September 01, 2008 11:23 AM
  • Another DataGrid bug found.  See this thread: http://silverlight.net/forums/t/27465.aspx

     

     

    Wednesday, September 17, 2008 10:48 AM
  • 3) If I have many columns in the DataGrid,  when I scroll to right to see all the columns, sometimes the data row are broken in the middle.
     

     

    i got the same problem here. i scroll right then it crashed. just size each column that will be solved. seems like a bug, the cell just can't re-size itself when scrolling............

    Sunday, May 24, 2009 10:22 PM