2

I have an object with several properties. However some of these properties contain information of the same group so to say. I would like to show these properties in a table in a way that in the same column i could put the properties of the same group. However I am not sure how to do that exactly. I do understand how to do it if i had several objects of the same type (put them in a list and get the default collection view source). But in this case i just have one object with several properties.

My question is: how could I bring these properties together to make one column in datagrid. all the properties are of same datatype (ushort).

Just to illustrate what i mean:


public ushort MyProperty1
{
    get{ return myProperty1}
    set
    {
       if(value==myProperty1)
         return;
       myProperty1=value;
       OnPropertyChanged("MyProperty1");    
    }
}

public ushort MyProperty2
{
    get{ return myProperty2}
    set
    {
       if(value==myProperty2)
         return;
       myProperty2=value;
       OnPropertyChanged("MyProperty2");    
    }
}

public ushort MyProperty3
{
    get{ return myProperty3}
    set
    {
       if(value==myProperty3)
         return;
       myProperty3=value;
       OnPropertyChanged("MyProperty3");    
    }
}

And i would like to show these properties in the same column of datagrid

Thanks :)

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
xnonamex
  • 405
  • 2
  • 5
  • 17

2 Answers2

2

You've got a few options to acieve your goal. You could use a MultiBinding with a StringFormat in a standard DataGridTextColumn.

Alternatively, you could define a DataTemplate and set it as the CellTemplate property of a DataGridTemplateColumn element.

I've included links to help get you started.

Sheridan
  • 68,826
  • 24
  • 143
  • 183
2

you can try the below one

    <DataGrid ItemsSource="{Binding Values}" AutoGenerateColumns="False">
        <DataGrid.Columns>
            <DataGridTemplateColumn Header="Values">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <TextBox Text="{Binding MyProperty1}"/>
                            <TextBox Text="{Binding MyProperty2}"/>
                            <TextBox Text="{Binding MyProperty3}"/>
                        </StackPanel>
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>
        </DataGrid.Columns>
    </DataGrid>
Kumareshan
  • 1,311
  • 8
  • 8
  • yeah. i was thinking about it. it's just that i have several of these tables and each has some 16 in 3 columns. so it's a bit of a mess in this case :) but thanks anyway ;) – xnonamex Nov 29 '13 at 15:31