Click here to Skip to main content
15,881,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a datagrid containing some data which is bind from a data table like:

Description | Value1 | Value2
Personal Details | |
Name | Xyz |Abc
Age |20 |12
Occupation |Student |Employee
Family Details: | |
Father |Aaa |Bba
Children |1 |2

It is having 3 columns. I want to merge the 2 other columns with 1st column when 2 other columns doesn't have any data(The particular row should only have a single column). Like:

Description |Value1 |Value2
Personal Details:
Name |Xyz |Abc
Age |20 |12
Occupation |Student|Employee
Family Details:
Father |Aaa |Bba
Children |1 |2


Can it be done with data grid or with any other control?
Posted

1 solution

Hi.You must define element style like this :
XML
<DataGridTextColumn.ElementStyle>
                            <Style TargetType="{x:Type TextBox}">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Subject}" Value="{x:Null}">
                                        <Setter Property="Width" TargetName="NameDataGridColumn" Value="0"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </DataGridTextColumn.ElementStyle>

and also you must set Header="". I hope this solution help you.
Good Luck
 
Share this answer
 
Comments
Tyagi Nitin 2-Mar-13 6:24am    
Hi Ali, you mean this style for first column? and in {Binding Subject} Subject is the first column binding? What do you mean by "NameDataGridColumn" in TargetName="NameDataGridColumn" here?

As you are saying the header to set "", but i need all three headers all the time.

What about if i use "datagrid.rowdetailstemplate"
This will show only the details from first column and it will be single column only.
Just i need to set the visibility on LodingRow event
DetailsVisibility = Windows.Visibility.Collapsed
and
e.Row.DetailsVisibility = Windows.Visibility.Visible

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900