Grid Object Binding Problem Help?

Hi,
I should show datagrid in diagram for the work which I study on it.
I created a new class which inherits BaseNetworkGraphObject class.I am creating a grid at constructor with bindings as below. At .cs side, after I set my list to itemsource, I added the grid on diagram.But the grid does not come with columns which I define with bindings.
I should do binding for datagrid dynamically at code.I wrote the code as below. When I debug this code block ,it seems that it does bindings correctly, but grid comes with no columns on form.


GridClass side :

MyClass myInstance=new MyClass ();
dataGridObject=new DataGrid();
dataGridObject.Width = 200;
dataGridObject.Height = 200;
binding = new Binding();
binding.Source = myInstance;
foreach (PropertyInfo prop in myInstance.GetType().GetProperties())
{
binding.Path = new PropertyPath(prop.Name);
DataGridTextColumn column=new DataGridTextColumn();
column.Header = prop.Name;
column.Binding=new Binding(prop.Name);
dataGridObject.Columns.Add(column);
}

.cs Side:

var model = this.objectDiagram.Model as GraphLinksModel<BaseNetworkGraphObject, string, string, BaseNetworkGraphLink>;
model.Modifiable = true;
model.HasUndoManager = true;
GridObject gridObject = new GridObject();
gridObject.DataGridObject.ItemsSource = e.Result;
gridObject.Key = “Key”;
gridObject.Nodetype = “NodeTemplateForGrid”;
model.AddNode(gridObject);
this.objectDiagram.StartTransaction(“Modify Node”);
objectDiagram.Model = model;
this.objectDiagram.CommitTransaction(“Modify Node”);

Why does’t come grid with columns, although I did necessary bindings?

There is another question I want to ask , I declared a nodetemplate which includes datagrid control.At MyClass, I am creating a datargid object according to the related table object.I bind DataGridObject.ItemsSource to Itemsource property at grid control ?Is there any other binding which should be declared?
Thanks for the replies in advance…

I suggest you try to do more in XAML. You can start with the EntityRelationship (ER) sample, which also includes a data grid in each node.

Hi Walter,
Firstly , thanks for the reply…
Actually I look at your sample ER. Diagram. My NodeTemplate is as below:

    <DataTemplate x:Key="NodeTemplateForGrid">
        <Border Background="Gray" BorderBrush="Gray" BorderThickness="2" CornerRadius="3" 
          go:Part.SelectionAdorned="True" go:Part.Resizable="True"
          go:Node.FromSpot="AllSides" go:Node.ToSpot="AllSides"
          go:Node.Location="{Binding Path=Data.Location, Mode=TwoWay}">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Grid Grid.Row="0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Column="0" HorizontalAlignment="Center"
                   Text="{Binding Path=Data.Key}" FontWeight="Bold" />
                    <Button Grid.Column="1" Content="*" Click="Button_Click" />
                </Grid>
                <sdk:DataGrid Grid.Row="1" AutoGenerateColumns="False"   HorizontalAlignment="Stretch"
                     Background="White" ItemsSource="{Binding Path=Data.DataGridObject.ItemsSource}" Width="{Binding Path=Data.Width}" Height="{Binding Path=Data.Height}" >
                </sdk:DataGrid>
            </Grid>
        </Border>
    </DataTemplate>

By the way , there are different objects which has different numbers of columns. Because of it, I did columns bindings at .cs side.

I am creating a DataGrid object at my own DataGridObjClass which inherits BaseNetworkGraphObject.

DataGrid dataGridObject = new DataGrid();
MyClass
myInstance =new
MyClass ();
dataGridObject.Width = 200;
dataGridObject.Height = 200;
binding = new Binding();
binding.Source =
myInstance ;
foreach (PropertyInfo prop in
myInstance .GetType().GetProperties())
{
binding.Path = new PropertyPath(prop.Name);
DataGridTextColumn column=new DataGridTextColumn();
column.Header = prop.Name;
column.Binding=new Binding(prop.Name);
dataGridObject.Columns.Add(column);
}

I tried to do the same binding for a normal grid at userControl page.It works correctly.Most probably I am creating the DataGrid correctly, but it is not added on model.

The diagram shows "the button and an empty datagrid " which I determine in nodetemplate. I suppose , the datagrid (which is created in DataGridObjClass ) is not associated with the datagrid in nodetemplate.I am doing something wrong but I couldn’t find it???
Thanks again for the reply in advance Walter…

You seem to be creating a DataGrid in the node’s DataTemplate, but then you create a separate DataGrid in code? You really ought to use the DataGrid that is created for each Node by your DataTemplate.

I can’t tell what your purpose is, but maybe you would be better off by letting DataGrid.AutoGenerateColumns=“True” and instead handle the DataGrid.AutoGeneratingColumn event so that you can customize or skip the columns that are added.

Hi Walter,
As you say, without doing any binding for each table, only setting “AutoGenerateColumns” to True solved my problem.
I have never thought that my situation will be solved by setting a property :)
Thank you for your time and answer.