Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WPF DataGrid
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-Mar-13 20:12pm

1 solution

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

Solution 1

Hi.You must define element style like this :
<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
  Permalink  
Comments
Tyagi Nitin at 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)

  Print Answers RSS
0 Maciej Los 315
1 OriginalGriff 273
2 Aajmot Sk 224
3 Marcin Kozub 210
4 Richard MacCutchan 200
0 OriginalGriff 7,853
1 Sergey Alexandrovich Kryukov 7,107
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,790


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 2 Mar 2013
Copyright © CodeProject, 1999-2014
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