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 9242225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:32:22+00:00 2026-06-18T08:32:22+00:00

In Wpf, Can I create a datagrid which different row contain different type of

  • 0

In Wpf, Can I create a datagrid which different row contain different type of control in same column?

For easiest case: datagrid with 5 cols, 2 rows, don’t care about 4 first cols, in 5th col:

  • 1st row: it’s a textbox
  • 2nd row: it’s a combobox.

Thanks!

  • 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-18T08:32:23+00:00Added an answer on June 18, 2026 at 8:32 am

    You can use a DataGridTemplateColumn combined with a few triggers to achieve this functionality.

    This is a demo application that binds a DataGrid to a list of (string) Control Types. The first column just displays the control type string, and the second column acts on the same information to present the corresponding Control. You might be able to make the xaml a bit more concise, but this is the jist of it:

    The XAML:

    <Window x:Class="DataGridWithMultipleTypesPerColumn.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <DataGrid ItemsSource="{Binding ControlTypes}"
                  AutoGenerateColumns="False">
            <DataGrid.Columns>
            <DataGridTextColumn Header="Control Type" Binding="{Binding}"/>
                <DataGridTemplateColumn Header="Actual Control">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <ContentControl>
                                <ContentControl.Style>
                                    <Style TargetType="ContentControl">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding}" Value="TextBox">
                                                <Setter Property="ContentTemplate">
                                                    <Setter.Value>
                                                        <DataTemplate>
                                                            <TextBox Text="Default Text"/>
                                                        </DataTemplate>
                                                    </Setter.Value>
                                                </Setter>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding}" Value="CheckBox">
                                                <Setter Property="ContentTemplate">
                                                    <Setter.Value>
                                                        <DataTemplate>
                                                            <CheckBox Content="Check Box"/>
                                                        </DataTemplate>
                                                    </Setter.Value>
                                                </Setter>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding}" Value="Button">
                                                <Setter Property="ContentTemplate">
                                                    <Setter.Value>
                                                        <DataTemplate>
                                                            <Button Content="Button"/>
                                                        </DataTemplate>
                                                    </Setter.Value>
                                                </Setter>
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </ContentControl.Style>
                            </ContentControl>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>
    </Grid>
    

    Code-behind and View Model:

    namespace DataGridWithMultipleTypesPerColumn
    {
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
                this.DataContext = new ViewModel();
            }
        }
    
        public class ViewModel
        {
            public ObservableCollection<string> ControlTypes
            {
                get;
                private set;
            }
            public ViewModel()
            {
                ControlTypes = new ObservableCollection<string>() { "Button", "TextBox", "CheckBox" };
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a custom wpf control, I'm wondering how I can
This walkthrough says you can create a WPF datagrid in one line but doesn't
In a WPF application, I can create an inherited property by using the FrameworkPropertyMetadata:
I just start learning WPF, is that possible I can create an IE toolbar
How can I create an TextBox in WPF ( With XAML ) that there
Using WPF .NET 4.0 in VS2010 RTM: I can't create a fullscreen WPF popup.
How to create a WPF application that can be deployed as either a XBAP
In WPF you can set the TargetType to either the name of the type
Basically, I'd like to make the WPF DataGrid control layout its columns exactly the
I am using a WPF c# application. I have a user control which contains

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.