Welcome to MSDN Blogs Sign in | Join | Help

Scott Morrison

The other Microsoft Scott
Defining Silverlight DataGrid Columns at Runtime
This post has been updated to work with the RTW version of the Silverlight 2 DataGrid.  The code examples are not guaranteed to work with previous Beta versions of the DataGrid. Read more about the features that the Silverlight 2 DataGrid has to offer...

Now that you know the basics of the Silverlight DataGrid and how to specify the Columns in XAML, you might want to customize your DataGrid's columns at runtime.

This process is pretty straight forward, so instead of doing the usual end-to-end walk through, I'm going to provide you with a Rosetta Stone between the static XAML form and the dynamic C#/VB form for the scenario in the last post.

Defining a DataGrid

For any of these columns to be useful you are going to first need a DataGrid to add them to.  The following creates a DataGrid, adds it as a child of the root layout Grid, and sets its ItemsSource to a collection called "source".

C#

DataGrid targetDataGrid = new DataGrid();
targetDataGrid.ItemsSource = source;
targetDataGrid.AutoGenerateColumns = false;
LayoutRoot.Children.Add(targetDataGrid);

VB

Dim TargetDataGrid As New DataGrid
TargetDataGrid.ItemsSource = Source
TargetDataGrid.AutoGenerateColumns = False
LayoutRoot.Children.Add(TargetDataGrid)

 

Defining a DataGrid Text Column

The following creates a DataGridTextColumn bound to the FirstName property with a header of "First Name", and adds it to the columns collection of the DataGrid named "targetDataGrid".

Static
 <data:DataGrid x:Name="targetDataGrid">
     <data:DataGrid.Columns>
         <data:DataGridTextColumn Header="First Name" 
             Binding="{Binding FirstName}" />
     </data:DataGrid.Columns>
 </data:DataGrid>
Dynamic

C#

using System.Windows.Data;
...
DataGridTextColumn textColumn = new DataGridTextColumn();
textColumn.Header = "First Name";
textColumn.Binding = new Binding("FirstName");
targetDataGrid.Columns.Add(textColumn);

VB

Imports System.Windows.Data
...
Dim TextColumn As New DataGridTextColumn
TextColumn.Header = "First Name"
TextColumn.Binding = New Binding("FirstName")
TargetDataGrid.Columns.Add(TextColumn)

 

Defining a DataGrid CheckBox Column

The following creates a DataGridCheckColumn bound to the Available property with a header of "Available", and adds it to the columns collection of the DataGrid named "targetDataGrid".

Static
 <data:DataGrid x:Name="targetDataGrid">
     <data:DataGrid.Columns>
         <data:DataGridCheckBoxColumn Header="Available " 
             Binding="{Binding Available}" />
     </data:DataGrid.Columns>
 </data:DataGrid>
Dynamic

C#

using System.Windows.Data;
...
DataGridCheckBoxColumn checkBoxColumn = new DataGridCheckBoxColumn();
checkBoxColumn.Header = "Available";
checkBoxColumn.Binding = new Binding("Available");
targetDataGrid.Columns.Add(checkBoxColumn);

VB

Imports System.Windows.Data
...
Dim CheckBoxColumn As New DataGridCheckBoxColumn
CheckBoxColumn.Header = "Available"
CheckBoxColumn.Binding = New Binding("Available")
TargetDataGrid.Columns.Add(CheckBoxColumn)

 

Defining a DataGrid Template Column

The following creates a DataGridTemplateColumn bound to the Birthday property with a header of "Birthday", and adds it to the columns collection of the DataGrid named "targetDataGrid".

Static
<UserControl.Resources>
    <local:DateTimeConverter x:Key="DateConverter" />
</UserControl.Resources>
...
<data:DataGrid x:Name="targetDataGrid" AutoGenerateColumns="False" >
    <data:DataGrid.Columns>
        <data:DataGridTemplateColumn Header="Birthday">
            <data:DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <TextBlock 
                        Text="{Binding Birthday, 
                        Converter={StaticResource DateConverter}}" 
                        Margin="4"/>
                </DataTemplate>
            </data:DataGridTemplateColumn.CellTemplate>
            <data:DataGridTemplateColumn.CellEditingTemplate>
                <DataTemplate>
                    <basics:DatePicker 
                        SelectedDate="{Binding Birthday, Mode=TwoWay}" />
                </DataTemplate>
            </data:DataGridTemplateColumn.CellEditingTemplate>
        </data:DataGridTemplateColumn>
    </data:DataGrid.Columns>
</data:DataGrid>
Dynamic

There are two ways to dynamically create a template column for a DataGrid.  One is to load in the CellTemplate and CellEditingTemplates as DataTemplates from resources, and the other is to construct the DataTemplates on the fly using XamlReader.

1. Resources Method

This method creates the CellTemplate DataTemplate and the CellEditingTemplate DataTemplate in XAML and stores them as named resources.  Then when the column is created the DataTemplates are used.

Use the below XAML to create the DataTemplates as resources to support the code for this method.

<UserControl.Resources>
    <local:DateTimeConverter x:Key="DateConverter" />

    <DataTemplate x:Key="myCellTemplate">
        <TextBlock 
            Text="{Binding Birthday, 
            Converter={StaticResource DateConverter}}" 
            Margin="4"/>
    </DataTemplate>

    <DataTemplate x:Key="myCellEditingTemplate">
        <basics:DatePicker 
            SelectedDate="{Binding Birthday, Mode=TwoWay}" />
    </DataTemplate>
</UserControl.Resources>

C#

using System.Windows.Data;
...
DataGridTemplateColumn templateColumn = new DataGridTemplateColumn();
templateColumn.Header = "Birthday";
templateColumn.CellTemplate = (DataTemplate)Resources["myCellTemplate"];
templateColumn.CellEditingTemplate = 
                       (DataTemplate)Resources["myCellEditingTemplate"];
targetDataGrid.Columns.Add(templateColumn);

VB

Imports System.Windows.Data
...
Dim TemplateColumn As New DataGridTemplateColumn
TemplateColumn.Header = "Birthday"
TemplateColumn.CellTemplate = Resources("myCellTemplate")
TemplateColumn.CellEditingTemplate = Resources("myCellEditingTemplate")
TargetDataGrid.Columns.Add(TemplateColumn)

2. XamlReader Method

This method creates the DataTemplate inline using the XamlReader class.  This class takes a string and parses it to try to build a visual tree.  In this case we are creating DataTemplates.  This method is especially useful if the DataTemplate itself has to be dynamic.  One example being if you wanted to modify what the element in the template was bound to.

Warning: This method is considerably more difficult than the resources method.  I recommend only using this if you need to dynamically create the DataTemplate.

Some things to watch out for:

  1. You will need to declare any XAML namespace that is used in the data template
  2. Any custom XAML namespace needs to specify both the clr-namespace and the assembly
  3. You cannot have white space between the xmlns: and the name of your namespace
  4. External resources cannot be referenced, they need to be declared inline
  5. The entire template is a single line, so if you get a XAML Parse exception, it will always say line 1, however the character is fairly accurate if you were to concatenate all of your lines.
  6. When using the StringBuilder approach shown below, make sure that you have the correct white space at the end of a line so that it is correctly separated when concatenated with the next line.

Now that the warnings are out of the way, here is how you do the equivalent of the code above:

C#

using System.Windows.Data;
using System.Windows.Markup;
using System.Text;
...
DataGridTemplateColumn templateColumn = new DataGridTemplateColumn();
templateColumn.Header = "Birthday";

StringBuilder CellTemp = new StringBuilder();
CellTemp.Append("<DataTemplate ");
CellTemp.Append("xmlns='http://schemas.microsoft.com/winfx/");
CellTemp.Append("2006/xaml/presentation' ");
CellTemp.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' ");

//Be sure to replace "YourNamespace" and "YourAssembly" with your app's 
//actual namespace and assembly here
CellTemp.Append("xmlns:local = 'clr-namespace:YourNamespace");
CellTemp.Append(";assembly=YourAssembly'>");

CellTemp.Append("<Grid>");
CellTemp.Append("<Grid.Resources>");
CellTemp.Append("<local:DateTimeConverter x:Key='DateConverter' />");
CellTemp.Append("</Grid.Resources>");
CellTemp.Append("<TextBlock ");
CellTemp.Append("Text = '{Binding Birthday, ");
CellTemp.Append("Converter={StaticResource DateConverter}}' ");
CellTemp.Append("Margin='4'/>");
CellTemp.Append("</Grid>");
CellTemp.Append("</DataTemplate>");

StringBuilder CellETemp = new StringBuilder();
CellETemp.Append("<DataTemplate ");
CellETemp.Append("xmlns='http://schemas.microsoft.com/winfx/");
CellETemp.Append("2006/xaml/presentation' ");
CellETemp.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' ");
CellETemp.Append("xmlns:basics='clr-namespace:System.Windows.Controls;");
CellETemp.Append("assembly=System.Windows.Controls' >");
CellETemp.Append("<basics:DatePicker ");
CellETemp.Append("SelectedDate='{Binding Birthday, Mode=TwoWay}' />");
CellETemp.Append("</DataTemplate>");

templateColumn.CellTemplate =
    (DataTemplate)XamlReader.Load(CellTemp.ToString());
templateColumn.CellEditingTemplate =
    (DataTemplate)XamlReader.Load(CellETemp.ToString());
targetDataGrid.Columns.Add(templateColumn);

VB

Imports System.Windows.Data
Imports System.Text
Imports System.Windows.Markup
...
Dim TemplateColumn As New DataGridTemplateColumn
TemplateColumn.Header = "Birthday"

Dim CellTemp As New StringBuilder
CellTemp.Append("<DataTemplate ")
CellTemp.Append("xmlns='http://schemas.microsoft.com/winfx/")
CellTemp.Append("2006/xaml/presentation' ")
CellTemp.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' ")

'Be sure to replace "YourNamespace" and "YourAssembly" with your app's 
'actual namespace and assembly here
CellTemp.Append("xmlns:local = 'clr-namespace:YourNamespace")
CellTemp.Append(";assembly=YourAssembly'>")

CellTemp.Append("<Grid>")
CellTemp.Append("<Grid.Resources>")
CellTemp.Append("<local:DateTimeConverter x:Key='DateConverter' />")
CellTemp.Append("</Grid.Resources>")
CellTemp.Append("<TextBlock ")
CellTemp.Append("Text = '{Binding Birthday, ")
CellTemp.Append("Converter={StaticResource DateConverter}}' ")
CellTemp.Append("Margin='4'/>")
CellTemp.Append("</Grid>")
CellTemp.Append("</DataTemplate>")
Dim CellETemp As New StringBuilder
CellETemp.Append("<DataTemplate ")
CellETemp.Append("xmlns='http://schemas.microsoft.com/winfx/")
CellETemp.Append("2006/xaml/presentation' ")
CellETemp.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' ")
CellETemp.Append("xmlns:basics='clr-namespace:System.Windows.Controls;")
CellETemp.Append("assembly=System.Windows.Controls' >")
CellETemp.Append("<basics:DatePicker ")
CellETemp.Append("SelectedDate='{Binding Birthday, Mode=TwoWay}' />")
CellETemp.Append("</DataTemplate>")
TemplateColumn.CellTemplate = XamlReader.Load(CellTemp.ToString())
TemplateColumn.CellEditingTemplate = XamlReader.Load(CellETemp.ToString())
targetDataGrid.Columns.Add(TemplateColumn)
Posted: Monday, April 14, 2008 3:25 PM by scmorris

Comments

Defining Silverlight DataGrid Columns at Runtime said:

Now that you know the <a href="http://blogs.msd

# April 15, 2008 2:59 AM

Rui Marinho said:

Hi there Scott, i m m trying to create de datagrid dynam but it dosen't show anything.. here is my code:

    DataGrid dataGrid = new DataGrid();

           dataGrid.GridlinesVisibility = DataGridGridlines.Horizontal;

           dataGrid.HeadersVisibility = DataGridHeaders.Column;

           dataGrid.ColumnWidth=85;

           dataGrid.RowHeight=30;

           if (operacao == "bomb")

           {

               //criar colunas dinamicas

               DataGridTextBoxColumn textBoxColumn = new DataGridTextBoxColumn();

               //criar header com sort

               HyperlinkButton hyperbut = new HyperlinkButton();

               hyperbut.Content = "Nº Int";

               hyperbut.Tag = "nint";

               hyperbut.Click += new RoutedEventHandler(Sort_Click);

               hyperbut.TextDecorations = TextDecorations.Underline;

               textBoxColumn.Header = hyperbut;

               textBoxColumn.DisplayMemberBinding = new Binding("nint");

               dataGrid.Columns.Add(textBoxColumn);

               DataGridTextBoxColumn textBoxColumn1 = new DataGridTextBoxColumn();

               //criar header com sort

               HyperlinkButton hyperbut1 = new HyperlinkButton();

               hyperbut1.Content = "Nome";

               hyperbut1.Tag = "nome";

               hyperbut1.Click += new RoutedEventHandler(Sort_Click);

               hyperbut1.TextDecorations = TextDecorations.Underline;

               textBoxColumn1.Header = hyperbut;

               textBoxColumn1.DisplayMemberBinding = new Binding("nome");

               dataGrid.Columns.Add(textBoxColumn1);

               DataGridTextBoxColumn textBoxColumn2 = new DataGridTextBoxColumn();

               //criar header com sort

               HyperlinkButton hyperbut2 = new HyperlinkButton();

               hyperbut2.Content = "Quadro";

               hyperbut2.Tag = "quadro";

               hyperbut2.Click += new RoutedEventHandler(Sort_Click);

               hyperbut2.TextDecorations = TextDecorations.Underline;

               textBoxColumn2.Header = hyperbut;

               textBoxColumn2.DisplayMemberBinding = new Binding("quadro");

               dataGrid.Columns.Add(textBoxColumn2);

# April 16, 2008 4:59 AM

scmorris said:

Hi Rui,

There are two things that could be missing from your code:

1) You are not setting the DataGrid's ItemsSource

2) You are not adding the DataGrid to the visual tree

I'll update the post to show how to add a DataGrid itself.  Let me know if you are doing both those things and still running into trouble.

Thanks,

Scott

# April 16, 2008 12:23 PM

Community Blogs said:

Corey Gaudin on The Next Web, Matt Casto&#39;s Scrolling Textbox, Martin Mihaylov with an Image Control

# April 16, 2008 1:59 PM

ScottGu's Blog said:

Here is the latest in my link-listing series .&#160; Also check out my ASP.NET Tips, Tricks and Tutorials

# April 29, 2008 1:35 AM

BusinessRx Reading List said:

Here is the latest in my link-listing series .&#160; Also check out my ASP.NET Tips, Tricks and Tutorials

# April 29, 2008 2:00 AM

Mirrored Blogs said:

Here is the latest in my link-listing series .&#160; Also check out my ASP.NET Tips, Tricks and Tutorials

# April 29, 2008 2:21 AM

Joycode@Ab110.com said:

【原文地址】 April 28th Links: ASP.NET, ASP.NET AJAX, ASP.NET MVC, Silverlight 【原文发表日期】 Monday, April 28, 2008

# April 29, 2008 11:04 PM

Scott Guthrie's Blog in Dutch said:

Hier vind je mijn laatste link-lijst series . Bekijk ook mijn ASP.NET Tips, Tricks and Tutorials pagina

# April 30, 2008 9:36 AM

ScottGu's Blog em Português said:

Aqui está a última versão da minha série de listas de links . Verifique também minha página de Dicas

# May 2, 2008 5:52 PM

Jordy said:

Is there a way to add a row in the datagrid? Something like this?

targetDataGrid.Rows.Add(templateRow)

# May 21, 2008 9:11 AM

Jordy said:

Is it also possible to add a DataRow in code behind?

For the Colums you can use: dataGridName.Columns.Add(columnName);

But there is no: dataGridName.Rows.Add(rowName);  You can define a datagridrow ( DataGridRow rowName = new DataGridRow() ), but than you can't add it to the dataGrid.

# May 28, 2008 3:34 AM

scmorris said:

Hi Jordy,

Unfortunately all of the rows in the Silverlight DataGrid need to have an equivalent item in the collection that it is bound to, and the "unbound" behavior that you are requesting is not supported currently in the DataGrid.  Depending on what you want to accomplish with the new rows there are a couple of paths you could take including adding proxies in your collection, or retemplating the DataGrid to have a row frozen at the bottom used for something like a totals row.

Hope this helps.

- Scott

# May 30, 2008 10:29 PM

Readed By Wrocław NUG members said:

Here is the latest in my link-listing series .&#160; Also check out my ASP.NET Tips, Tricks and Tutorials

# June 15, 2008 11:27 AM

Alphatester001 said:

Hi,

with the xamlReader how do you add an event handler? - if you define it within the stringBuilder, the xamlReader throw an exception. I tried to define it through a style in a ResourceDictionary that I merge later on. If I look for style entry in the resourceDictionary it is there, same for the dataTemplate,but I get an error when the control get rendered. the error is : Cannot find resource named '{mystyle}'. Resource names are case sensitive.  Error at object 'System.Windows.Controls.ComboBox' . I double checked in the template I referred to mystyle and same  thing in my second dictionary.So error message is inappropriate. It is more an issue to locate the style in the dictionary... any clue?

# June 27, 2008 4:01 AM

rtr0mdrn said:

Scott, I would like to know how to add a column dynamically after all autogenerated columns have been created.  In other words I would like for the grid to generate columns using the binding context, and after this has completed insert a more static or functional column (such as a button) which can be used to interact with the bound data or add additional features.  I see the autogenerating column event but there does not appear to be any eventing related to binding having completed or all column generation completed.  Is it possible to mix autogeneration with static column insertion and if so how best to do this at runtime?  Thanks.

# July 17, 2008 10:03 AM

johnzabroski said:

Is it okay to specify a ConverterParameter using XML literals in the C# code behind?  I basically copied your XML literal example verbatim, but added a ConverterParameter and instead of the source value being a property, it was a whole collection with the ConverterParameter used as a key to pick an item in the collection.  Sort of like LINQifying David Anson's IValueConverter SwissArmyKnife PropertyViewer.

# July 17, 2008 9:54 PM

johnzabroski said:

Scott,

I am not sure your code here is 100% correct.  You show how to dynamically construct XAML using a CLR StringBuilder and then pass that into XamlReader.Load(string).  Do XML fragments have to be fully-qualified using <?Mapping XmlNamespace="blah" ClrNamespace="clr-blah-app" Assembly="blah-assembly" ?> ?

I keep getting ManagedRuntime 4004 exceptions when I try to use your approach above.

# July 18, 2008 2:31 PM

木野狐(Neil Chen) said:

(以下内容全部整理自博客堂Scottgu博客中文版)Silverlight技巧,诀窍,教程和链接 【原文地址】SilverlightTips,Tricks,...

# July 21, 2008 10:36 PM

SLNewb said:

The columns part of this is real handy.  

For the resources method, it would be helpful to me for the example to include the following:

- reference necessary for dateconverter (or class def), can't seem to find this in my project.

- xmlns definition required

- example of locating this resource template outside the control.xaml (which seems to be the most likely usage, yes?)

# September 18, 2008 5:45 AM

oneone said:

is possible to add a listbox ?

# October 1, 2008 2:39 AM

Scott Morrison said:

As you might have heard , we just released Silverlight 2 , and with it the first version of the Silverlight

# October 15, 2008 2:46 AM

Ronnie Meijer said:

I have a simple datagrid and I want to align one column to the right.

Is there a way to do this dynamically.

# October 17, 2008 5:37 PM

marjolein said:

How can I bind a two-dimensional object? So I don't know in advance how many columns there are. Each columns contains a set of values. The itemSource of my datagrid is the collection of columns, but what is then the binding of my value in the columns?

      Column1  Column2 ...

Item 1    0        6

Item 2    1        8

Item 3    5        0

...

# November 4, 2008 7:34 AM

Hema said:

To display a cell having multiple columns at runtime i would like to have a datagridcolumn on cell click or a datagridcomboboxcolumn which can display multiple columns at runtime

# December 3, 2008 3:59 AM

Andrus said:

How to add event handler using XamlReader.Load method ?

Code below causes exception AG_E_PARSER_BAD_PROPERTY_VALUE

I tried to move AddToCart_Click method to Page class but problem persists.

Or is it possible to set click event handler in code ?

Andrus.

Page.xaml:

<UserControl xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"  x:Class="DataGridDynamicColClickHandler.Page"

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

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

  xmlns:myGrid="clr-namespace:DataGridDynamicColClickHandler"

>

   <Grid x:Name="LayoutRoot" Background="White">

       <myGrid:DataGridBase x:Name="InventoryList"></myGrid:DataGridBase >

   </Grid>

</UserControl>

Page.xaml.cs:

using System.Windows;

using System.Windows.Controls;

using System.Windows.Markup;

namespace DataGridDynamicColClickHandler

{

   public partial class Page : UserControl

   {

       public Page()

       {

           InitializeComponent();

           InventoryList.Create();

       }

   }

   public class Product

   {

       public string Name { get; set; }

   }

   public class DataGridBase : DataGrid

   {

       public void Create()

       {

           ItemsSource = new Product[] { new Product { Name = "Apple" }};

           DataGridTemplateColumn xtemplateColumn = new DataGridTemplateColumn();

           xtemplateColumn.CellTemplate = XamlReader.Load(string.Format(@"<DataTemplate

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

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

xmlns:myGrid=""clr-namespace:DataGridDynamicColClickHandler""

>

<Button Click=""AddToCart_Click"" />

</DataTemplate>"

)) as DataTemplate;

           Columns.Add(xtemplateColumn);

       }

       public void AddToCart_Click(object sender, RoutedEventArgs e)

       {

       }

    }

}

# February 21, 2009 1:39 PM

Jason Young said:

Hi Scott, any idea how I can get a frozen column on the right hand side of the grid?

# March 6, 2009 3:55 PM

Beto said:

Hi, when i use the below XAML to create the DataTemplates as resources to support the code for this method.

<UserControl.Resources>

   <local:DateTimeConverter x:Key="DateConverter" />

   <DataTemplate x:Key="myCellTemplate">

       <TextBlock

           Text="{Binding Birthday,

           Converter={StaticResource DateConverter}}"

           Margin="4"/>

   </DataTemplate>

Blend close in same time !!!!!

just paste de follow xaml :  

Converter={StaticResource DateConverter}}"

Makes the Blend close , a messageBox show a internal error . please help!!!

sorry my bad inglish!

Thanks

# March 10, 2009 5:43 PM

John said:

Has anyone added a summary /totals to a templated data grid (other than devexpress) ... or to a plain grid?  

Did you use grid/cell events to trigger recalculation once changes were made to the underlying observable collection?

# March 11, 2009 12:27 PM

Rick Kierner said:

Good post.  Very helpful.  It's working for me the way you've explained it.  I'm creating dynamic data columns just fine.  My problem is when I want to handle the click event or text changed event of one of my columns.  If I use a static column template, the event will fire.  If I use a dynamic template, I get a parse error identifying the Click="MyClickEventHandler" section of code.  Ideas?

# March 25, 2009 1:38 PM

Tony said:

Hi Scott;

How can some access control in datagrid ?

# April 7, 2009 1:09 AM

Servando said:

I'm using Silverlight 2.0 and trying the XamlReader Method.

I'm doing a basic sample with just one column, added stackpanel to the page and a datagrid with name TestGrid to the panel.

My project's name is DBGridTest, the class' name is the default (Page).

I changed your code and instead of YourNamespace putted "DBGridTest" which is the namespace for my project

and instead of YourAssembly putted "DBGridTest.Page".

I have a class with Birthday property of DateTime type, just that property for now.

I create a generic List of theis class and add 5 elements to it.

Then in the Page constructor after InitializeComponent() y put the following:

           TestGrid.Columns.Add(templateColumn);

           TestGrid.AutoGenerateColumns = false;

           TestGrid.ItemsSource = employeelist;

When I set the Datagrid height small so that only the headers are shown it runs ok.

But if I change the height so that the column's content will would be shown the iexplore.exe throws and exception 5828.

when instead of adding the columns I set AutoGenerateColumns = true; it all runs ok.

Am I missing a property on the DataGrid or something else?

# June 16, 2009 8:49 PM

Kamran said:

Thanks for the great post. I've referred to it several times :)

# July 19, 2009 3:18 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker