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

GridView.Count always 0

7 Answers 92 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Marco
Top achievements
Rank 1
Marco asked on 04 Nov 2009, 09:35 PM
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

7 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 05 Nov 2009, 01:24 PM
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.
0
Marco
Top achievements
Rank 1
answered on 05 Nov 2009, 03:18 PM
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
0
Vlad
Telerik team
answered on 05 Nov 2009, 03:20 PM
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.
0
Marco
Top achievements
Rank 1
answered on 05 Nov 2009, 03:35 PM
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
0
Vlad
Telerik team
answered on 05 Nov 2009, 04:04 PM
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.
0
Marco
Top achievements
Rank 1
answered on 05 Nov 2009, 08:31 PM
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
0
Vlad
Telerik team
answered on 06 Nov 2009, 06:50 AM
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.
Tags
GridView
Asked by
Marco
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Marco
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or