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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:06:57+00:00 2026-05-16T10:06:57+00:00

Is it possible to bind two different data to the same DataGrid column. Say

  • 0

Is it possible to bind two different data to the same DataGrid column. Say if I have class A which has the Property p1 and I have another class B with the Property p2. Is it possible to bind p1 and p2 to the same datagrid column?

  • 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-05-16T10:06:57+00:00Added an answer on May 16, 2026 at 10:06 am

    Something like this:

    <StackPanel>
       <TextBlock Text="{Binding ClassAProperty}"/>
       <TextBlock Text="{Binding ClassBProperty}"/>
    </StackPanel>
    

    will work, so long as the classes don’t have any properties with the same name. But that’s a kind of ugly hack, and good luck finding real binding errors among all of the spurious binding errors that this approach will generate.

    The mapping of each types’ properties to columns has to live somewhere, but it doesn’t have to live in XAML, and that’s not where I’d put it. I’d do it in my view model. Assuming that I don’t already have view model classes for my ClassA and ClassB objects (and that I don’t want to create them), I’d implement something like this:

    public class DataGridHelper
    {
       public Wrapper(object o)
       {
          ClassA a = o as ClassA;
          if (a != null)
          {
             Column1 = a.Property1;
             Column2 = a.Property2;
             ...
          }
    
          ClassB b = o as ClassA;
          if (b != null)
          {
             Column1 = b.Property1;
             Column2 = b.Property2;
             ...
          }
    
          public object Column1 { get; private set; }
          public object Column2 { get; private set; }
    }
    

    …and then bind the DataGrid‘s columns to a collection of DataGridHelper objects.

    If I did have ClassAViewModel and ClassBViewModel classes, I’d just implement Column1, Column2, etc. properties in both. That’d be the way to go if I needed to support two-way binding and validation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 529k
  • Answers 529k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Okay, I don't fully understand what you are doing, so… May 16, 2026 at 11:19 pm
  • Editorial Team
    Editorial Team added an answer What you need are character classes. In that, you've only… May 16, 2026 at 11:19 pm
  • Editorial Team
    Editorial Team added an answer you can use getJSON for example $.getJSON('ajax/test.json', function(data) { $('.result').html('<p>'… May 16, 2026 at 11:19 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Is that possible to bind two dataset at a same time in asp.net crystal
Is it possible to bind a particular column in datagridview to another datasource, while
it is possible to bind Live('hover') and bind('contextmenu') on the same .class? This code
Using WPF, is it possible to bind two source properties, via one-way binding, to
Is it possible to bind a ComboBox to a list of objects, but have
Is it possible to bind all widgets to one command, with a single line?
I was wondering if it is possible to bind an array of integers as
I'm having some problems displaying the contents of one NSArrayController in two windows defined
I'm about to start a new ASP.NET MVC application. In it we have a
I have the following prepared query I am using with mysql and php. It

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.