Click here to Skip to main content
13,085,292 members (54,686 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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-Mar-13 19:12pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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

and also you must set Header="". I hope this solution help you.
Good Luck
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
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170813.1 | Last Updated 2 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100