GridView.Count always 0

8 posts, 0 answers
  1. Marco
    Marco avatar
    23 posts
    Member since:
    Apr 2009

    Posted 04 Nov 2009 Link to this post

    Hello,

    I just upgraded to 2009.Q3 and, I'm struggling with the migration from Q2 to Q3.  Is there any good resource I can go to "do what I did with Q2 in Q3"?   A translation from the obsolete properties/methods to the new ones would be highly appreciated

    Ok, the concrete issue I'm seeing right now is related to the code below (minimalist version):

    myGrid.ItemsSource = myDataTable;
    myGrid.AutoGeneratingColumn += myGrid_AutoGeneratingColumn;

    After performing these operations, I see that myDataTable.Columns.Count = 25 and myGrid.Columns.Count = 0, and the event handler AutoGeneratingColumn is never executed.

    Please help,
    Marco
  2. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 05 Nov 2009 Link to this post

    Hello Marco,

    To get the AutoGeneratingColumn event you should first attach the handler then set ItemsSource.
    myGrid.AutoGeneratingColumn += myGrid_AutoGeneratingColumn;
    myGrid.ItemsSource = myDataTable;

    Let us know if you need more information.

    Kind regards,
    Hristo
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Marco
    Marco avatar
    23 posts
    Member since:
    Apr 2009

    Posted 05 Nov 2009 Link to this post

    Hello Hristo,
    I just tried it and I don't know why but it's not working.

    However, the main issue I'm having with my code is that after binding the datatable to the grid, I loop through the columns to set some attributes to each column based on info stored in a database like Header, IsVisible, IsReadOnly, Width, whether it's a comboBox or not, etc.  This used to work in Q2, but right now the columns collection is getting empty.

    I'd appreciate if you can help me, if not, I will need to rollback the controls back to Q2, and the customer would not experience the significant performance improvement you introduced in Q3.

    Regards,
    Marco
  5. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 05 Nov 2009 Link to this post

    Hi Marco,

    Can you send us an example demonstrating not working AutoGeneratingColumn event?

    Regards,
    Vlad
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  6. Marco
    Marco avatar
    23 posts
    Member since:
    Apr 2009

    Posted 05 Nov 2009 Link to this post

    Hi,
    Thanks for the quick response.

    I'm sorry for the confusion, the discrepancy about the AutoGeneratingColumn event is not the real issue, I initially put it because I thought it was related to my original problem.
    What I do really care about is the fact that the columns collection is empty after the binding.

    "However, the main issue I'm having with my code is that after binding the datatable to the grid, I loop through the columns to set some attributes to each column based on info stored in a database like Header, IsVisible, IsReadOnly, Width, whether it's a comboBox or not, etc.  This used to work in Q2, but right now the columns collection is getting empty.

    I'd appreciate if you can help me, if not, I will need to rollback the controls back to Q2, and the customer would not experience the significant performance improvement you introduced in Q3."


    Regards,
    Marco
  7. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 05 Nov 2009 Link to this post

    Hi Marco,

    I've attached an example project.

    Kind regards,
    Vlad
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  8. Marco
    Marco avatar
    23 posts
    Member since:
    Apr 2009

    Posted 05 Nov 2009 Link to this post

    Hello,
    I've been playing with your solution and I'm getting a different error now.
    Please see the code below:

    Xaml:
     
    <Window x:Class="WpfApplication1.Window1" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView" 
        Title="Window1" Height="400" Width="300"
        <StackPanel Orientation="Vertical">         
            <telerik:RadGridView x:Name="RadGridView1" Height="300"/> 
            <Button Height="40" Width="120" Click="Button_Click">Apply grid attributes</Button> 
        </StackPanel> 
    </Window> 




    C#:
    public partial class Window1 : Window 
        { 
            public Window1() 
            { 
                InitializeComponent(); 
     
                var table = new DataTable(); 
                for (var i = 0; i < 6; i++ )   // Adding columns 
                   table.Columns.Add(new DataColumn("Column" + i, typeof(string))); 
     
                for (var i = 0; i < 10; i++)     // Adding some rows 
                    table.Rows.Add(new object[] { i, String.Format("Name{0}", i) }); 
                 
                RadGridView1.ItemsSource = table
            } 
     
            private void Button_Click(object sender, RoutedEventArgs e) 
            { 
                //With 5 columns runs fine,  
                //With 6 columns throws an 'Object reference not set to an instance of an object' exception 
                foreach (var col in RadGridView1.Columns) 
                    col.Header = "Hello"
            } 
        } 

    When I modify the Header of the columns, depending on the number of columns in the grid it throws an exception on the 5th column.

    Do you know why this is happening?  How can I solve it?

    Thanks for your help,
    Marco
  9. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 06 Nov 2009 Link to this post

    Hi Marco,

    You are right about this - fixed immediately! The fix will be part of our first Q3 internal build today.

    Greetings,
    Vlad
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top
UI for WPF is Visual Studio 2017 Ready