Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8730277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:59:20+00:00 2026-06-13T08:59:20+00:00

I have a datagrid in my form which has columns for each of Question

  • 0

enter image description hereI have a datagrid in my form which has columns for each of Question Types.
I want that column to be split into two as i want to accept number of compulsory and number of optional questions for each of the question type in the subsequent columns.

I have achieved this in winforms, thanks to stackoverflow.com.

I am trying to achieve the same in WPF

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:59:21+00:00Added an answer on June 13, 2026 at 8:59 am

    I guess this is the DataGrid layout you want…. right?

    .------.-----------------.--------.
    |      |   ID Details    |        |
    | Name |-----------------| Status |
    |      | ID   | Passport |        |
    |------|------|----------|--------|
    |X     | 123  | E567868  | Present|
    |Y     | 236  | 7875678  | Absent |
    '------'------'----------'--------'
    

    WPF datagrid doesnt support this readily. But you can do some stretchy coding. The code like below can split the headers. You need to take caution that …

    When the split columns are reordered (DataGrid.ColumnReordered
    event), all the sibling columns under their common parent header should be
    moved, together. I am leaving that code to you.

    Have some custom styles for DataGridHeaders

    <Style TargetType="{x:Type Primitives:DataGridColumnHeader}" 
      x:Key="SplitHeaderStyle">
    <Setter Property="VerticalContentAlignment" Value="Center" />
    <Setter Property="Template">
        <Setter.Value>
        <ControlTemplate TargetType="{x:Type Primitives:DataGridColumnHeader}">
            <DockPanel LastChildFill="True">
            <Grid DockPanel.Dock="Bottom">
                <Controls:DataGridHeaderBorder 
                SortDirection="{TemplateBinding SortDirection}"
                IsHovered="{TemplateBinding IsMouseOver}"
                IsPressed="{TemplateBinding IsPressed}"
                IsClickable="{TemplateBinding CanUserSort}"
                Background="{TemplateBinding Background}"
                BorderBrush="{TemplateBinding BorderBrush}"
                BorderThickness="{TemplateBinding BorderThickness}"
                Padding ="{TemplateBinding Padding}"
                SeparatorVisibility="{TemplateBinding SeparatorVisibility}"
                SeparatorBrush="{TemplateBinding SeparatorBrush}">
                <ContentPresenter 
                Content="{Binding RelativeSource={RelativeSource TemplatedParent},
                          Path=Content[0]}"
                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                HorizontalAlignment="Center"/>
                </Controls:DataGridHeaderBorder>
                <Thumb x:Name="PART_LeftHeaderGripper"
                   HorizontalAlignment="Left"
                   Style="{StaticResource ColumnHeaderGripperStyle}"/>
                <Thumb x:Name="PART_RightHeaderGripper"
                   HorizontalAlignment="Right"
                   Style="{StaticResource ColumnHeaderGripperStyle}"/>
            </Grid>
            <Grid DockPanel.Dock="Top">
                <Controls:DataGridHeaderBorder
                HorizontalAlignment="Stretch"
                IsClickable="False"
                Background="{TemplateBinding Background}"
                BorderBrush="{TemplateBinding SeparatorBrush}"
                BorderThickness="{TemplateBinding BorderThickness}"
                Padding ="{TemplateBinding Padding}"
                SeparatorVisibility="{TemplateBinding Tag}"
                SeparatorBrush="{TemplateBinding SeparatorBrush}">
                <ContentPresenter 
                    Content="{Binding RelativeSource={RelativeSource TemplatedParent}, 
                              Path=Content[1]}"
                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                    Margin="-8,2,-10,2"/>
                </Controls:DataGridHeaderBorder>
                <Thumb x:Name="PART_LeftSplitHeaderGripper"
                HorizontalAlignment="Right"
                Visibility="{TemplateBinding Tag}"
                Style="{StaticResource ColumnHeaderGripperStyle}"/>
            </Grid>
            </DockPanel>
        </ControlTemplate>
        </Setter.Value>
    </Setter>
    </Style>
    
    <Style TargetType="{x:Type Primitives:DataGridColumnHeader}" 
       BasedOn="{StaticResource SplitHeaderStyle}"
       x:Key="SplitHeaderLeftStyle">
    <Setter Property="HorizontalContentAlignment" Value="Left"/>
    <Setter Property="Tag" Value="{x:Static Visibility.Visible}"/>
    </Style>
    
    <Style TargetType="{x:Type Primitives:DataGridColumnHeader}" 
       BasedOn="{StaticResource SplitHeaderStyle}"
       x:Key="SplitHeaderRightStyle">
    <Setter Property="HorizontalContentAlignment" Value="Right"/>
    <Setter Property="Tag" Value="{x:Static Visibility.Collapsed}"/>
    </Style>
    

    Have columns arranged like this…

    <Controls:DataGrid.Columns>
    <Controls:DataGridTextColumn 
             Header="Name" 
             Binding="{Binding Name}"/>
    <Controls:DataGridTextColumn 
             Binding="{Binding ID}" 
        HeaderStyle="{StaticResource SplitHeaderRightStyle}">
        <Controls:DataGridTextColumn.Header>
        <x:ArrayExtension Type="System:String">
            <System:String>ID</System:String>
            <System:String>ID De</System:String>                            
        </x:ArrayExtension>
        </Controls:DataGridTextColumn.Header>
    </Controls:DataGridTextColumn>
    <Controls:DataGridTextColumn 
             Binding="{Binding Passport}"
        HeaderStyle="{StaticResource SplitHeaderLeftStyle}">
        <Controls:DataGridTextColumn.Header>
        <x:ArrayExtension Type="System:String">
            <System:String>Passport</System:String>
            <System:String>tails</System:String>                            
        </x:ArrayExtension>
        </Controls:DataGridTextColumn.Header>
    </Controls:DataGridTextColumn>
    <Controls:DataGridTextColumn 
                Header="Status"
                Binding="{Binding Status}"/>
      </Controls:DataGrid.Columns>
    

    So basically you use the same default header layout of DataGrid but hack it in a way that two headers look like they are joined together.

    C#

    1. Name your DataGrid e.g. x:Name="MyDataGrid".
    2. Keep all the styles in XAML in <DataGrid.Resources ..> tag. Make sure that they have x:Key set. e.g. x:Key="SplitHeaderLeftStyle" & x:Key="SplitHeaderRightStyle"

      <DataGrid x:Name="MyDataGrid">
           <DataGrid.Resources>
               <Style 
                    TargetType="{x:Type Primitives:DataGridColumnHeader}" 
                    x:Key="SplitHeaderStyle" .../>
      
               <Style x:Key="SplitHeaderLeftStyle" 
                      BasedOn="{StaticResource SplitHeaderStyle}".../>
      
               <Style x:Key="SplitHeaderRightStyle"
                      BasedOn="{StaticResource SplitHeaderStyle}" .../>
           </DataGrid.Resources>
           ...
      </DataGrid> 
      
    3. in your C# code when you add columns, set the styles by their Key.

        var dgIDColumn 
          = new DataGridTextColumn()
            {
              Header = new string[] { "ID", "ID Det" },
              Binding = new Binding() { Path = new PropertyPath("ID") },
              HeaderStyle = MyDataGrid.FindResource("SplitHeaderRightStyle") as Style;
            };
      
       MyDataGrid.Columns.Add(dgIDColumn);
      
        var dgPassportColumn 
         = new DataGridTextColumn()
           {
              Header = new string[] { "Passport", "ails" },
              Binding = new Binding() { Path = new PropertyPath("Passport") },
              HeaderStyle = MyDataGrid.FindResource("SplitHeaderLeftStyle") as Style;
           };
      
        MyDataGrid.Columns.Add(dgPassportColumn);
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DataGrid and it has a DataGridTextColumn that has items which I
I have a DataGrid bound to a DataView which, among other columns has, an
I have a DataGrid that represents layers - each row is an image on
I have a datagrid control in my project which has a combobox control manually
I have 2 silverlight controls on a form; datagrid which is bound to list
I have a WinForms project with a form that incorporates a datagrid. I have
I have two threads that are declared global.On the form load i start the
I have a web form that binds a DataGrid to a, normally, different data
I have a windows form with DataBound DataGrid on it. Bound to a list
I have a datagrid in C#.net I have made some columns in grid editable.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.