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

Unable to add columns to GridView at runtime

4 Answers 106 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sandi
Top achievements
Rank 1
Sandi asked on 14 May 2009, 07:12 PM
An unhandled exception of type 'System.OutOfMemoryException' occurred in Unknown Module.

A simple example of adding columns at runtime is causing the above error. Ideas anyone? Am I missing something?
The project is building and running fine untile it runs out of memory.

Thanks in advance for your help.

Sandi

xaml is:

<

 

UserControl x:Class="TestTelerik.MainPage"  

 

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  

 

 

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

 

xmlns:grid="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView" 

 

 

 

xmlns:gridView="clr-namespace:Telerik.Windows.Controls.GridView;assembly=Telerik.Windows.Controls.GridView" >

 

 

 

 

 

<Grid x:Name="LayoutRoot" >
<Grid.RowDefinitions>
<RowDefinition Height="25"/>

 

<RowDefinition Height="*"/>

 

 

</Grid.RowDefinitions>

 

 

 

<grid:RadGridView Grid.Row="1" x:Name="dataGrid" AutoGenerateColumns="False" ColumnsWidthMode="Auto" CanUserFreezeColumns="False" />

 

 

</Grid>

 

 </

 

UserControl>

 

 

 



Underlying code is:

using

 

System;  

 

 

using

 

System.Collections;  

 

 

using 

 

System.Collections.Generic;

 

 

using System.Collections.ObjectModel;

 

 

using System.Linq;

 

 

using System.Net;

 

 

using System.Windows;

 

 

using System.Windows.Controls;

 

 

using System.Windows.Documents;

 

 

using System.Windows.Input;

 

 

using System.Windows.Media;

 

 

using System.Windows.Media.Animation;

 

 

using System.Windows.Shapes;

 

 

using Telerik.Windows.Controls;

 

 

 

namespace 

 

TestTelerik

 

 { 

 

public partial class MainPage : UserControl  

 

 

{

public MainPage()  

 

{

InitializeComponent(); 

 

this.dataGrid.AutoGenerateColumns = false

 

this.dataGrid.Columns.Add(CreateColumn(typeof(int), "OrderID"));  

 

 

this.dataGrid.Columns.Add(CreateColumn(typeof(string), "Employee.FirstName"));

 

this.dataGrid.Columns.Add(CreateColumn(typeof(string), "Employee.LastName"));

 

 

this.dataGrid.Columns.Add(CreateColumn(typeof(string), "Employee.HomePhone"));

 

 }

 

 

private static GridViewDataColumn CreateColumn(Type columnType, string dataPath)

 

GridViewDataColumn dataGridColumn = new GridViewDataColumn();  

dataGridColumn.DataType = columnType;

dataGridColumn.UniqueName = dataPath;

dataGridColumn.HeaderText = dataPath; 

 

return dataGridColumn; 
}

}

}

 


4 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 15 May 2009, 06:01 AM
Hello Sandi,

I just tried your code however everything worked fine on my end - you can find an example project attached.

All the best,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
rwozniak
Top achievements
Rank 1
answered on 17 Jun 2009, 03:08 AM
I'm running into the same error w/ basic databinding against the following internal build:

Latest Version: 2009.1 526 (May 26, 2009)

XAML:

<

 

UserControl x:Class="GridViewTest.MainPage"

 

 

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

 

 

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

 

 

xmlns:telerikGridView="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"

 

 

Width="400" Height="300">

 

 

 

 

<Grid x:Name="LayoutRoot">

 

 

 

<telerikGridView:RadGridView x:Name="MessagesGrid" />

 

 

 

</Grid>

 

 

</

 

UserControl>

Code-Behind:

 

 

 

using

 

System.Collections.ObjectModel;

 

 

 

using

 

System.Windows;

 

 

 

namespace

 

GridViewTest

 

{

 

public partial class MainPage

 

 

 

 

{

 

public MainPage()

 

{

InitializeComponent();

Loaded += MessagesLoaded;

}

 

void MessagesLoaded(object sender, RoutedEventArgs e)

 

{

LoadMessages();

}

 

private void LoadMessages()

 

{

MessagesGrid.ItemsSource = GetMessages();

}

 

private static ObservableCollection<Message> GetMessages()

 

{

 

return new ObservableCollection<Message>

 

{

 

new Message {Body = "Check# 1", Subject = "Item 1", Time = "June, 1 13:45"},

 

 

new Message {Body = "Check# 2", Subject = "Item 2", Time = "June, 1 13:45"},

 

 

new Message {Body = "Check# 3", Subject = "Item 3", Time = "June, 1 13:45"}

 

};

}

}

 

public class Message

 

 

 

 

{

 

public string Subject { get; set; }

 

 

public string Time { get; set; }

 

 

public string Body { get; set; }

 

}

}

 

0
rwozniak
Top achievements
Rank 1
answered on 17 Jun 2009, 11:20 AM
By the way, the error is related to databinding. If I comment out the following line I do not get the error (of course I also do not see the data in the grid).

MessagesGrid.ItemsSource = GetMessages();
0
Hristo Deshev
Telerik team
answered on 17 Jun 2009, 11:59 AM
Hi rwozniak,

That seems odd. I am unable to reproduce the problem. I copied your code verbatim, and I used the latest (June 12) internal build.

I am attaching a sample project that works for me. Does it work on your end?

Sincerely yours,
Hristo Deshev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
General Discussions
Asked by
Sandi
Top achievements
Rank 1
Answers by
Vlad
Telerik team
rwozniak
Top achievements
Rank 1
Hristo Deshev
Telerik team
Share this question
or