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

  • Home
  • SEARCH
  • 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 8198711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:00:31+00:00 2026-06-07T06:00:31+00:00

I am trying to populate a datagrid with one column as a combobox but

  • 0

I am trying to populate a datagrid with one column as a combobox but I need that when the collection binded to the combobox is empty the column becomes a textbox column. I have defined the columns as below:

Binding binding = new Binding(“DataContext.Prices”);
binding.RelativeSource = new RelativeSource(RelativeSurceMode.FindAncestor, typeof(UserControl),1);

DataGridComboBoxColumn productPrices = new DataGridComboBoxColumn()
{
   ElementSyle = new Style
   {
        TargetType = typeof(ComboBox),
        Setters =
        {
            new Setter
            {
                Property=ComboBox.ItemsSourceProperty,
                Value= binding
            }
        }
   },
   EditingElementSyle = new Style
   {
        TargetType = typeof(ComboBox),
        Setters =
        {
            new Setter
            {
                Property=ComboBox.ItemsSourceProperty,
                Value= binding
            }
        }
   },
   DisplayMemberPath = new Binding("Price");
   SelectedValuePath = new Bindnt("Price");
};

myDataGrid.Columns.Add(productPrices);
myDataGrid.Columns.Add(new DataGridTextColumn(){ Header="Name", Binding=new Binding("Name")});

And I defined myDataGrid:

<DataGrid Name="myDataGrid" ItemsSource="{Binding Products}" />

In my viewmodel I create a

var products = new List<Product>
{
    new Product 
    {
       Name="Prod 1",
       Price="12.5"
    }
}
var prices = new List<PriceL>
{
    new PriceL
    {
       Price="12.5"
    },
    new PriceL
    {
       Price="10"
    }

}

ICollectionView Products = CollectionViewSource.GetDefaultView(products);
ICollectionView Prices = CollectionViewSource.GetDefaultView(prices);

I need that when “Prices” is empty the column become in a textbox I am working with MVVM and I tried with elementStyle but I cannot see any event in Combobox that let me verify it’s data source. Could any body help me ??

  • 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-07T06:00:33+00:00Added an answer on June 7, 2026 at 6:00 am

    I just found one way to do that

    <UserControl.Resources>
        <DataGrid ItemsSource={binding} x:Key="DataGrid1">
            <DataGrid.Columns>
                <DataGridTextColumn Binding="{ID}"/>
                <DataGridTextColumn Binding="{Name}"/>
            </DataGrid.Columns>
        </DataGrid>
        <DataGrid ItemsSource={binding} x:Key="DataGrid2">
            <DataGrid.Columns>
                <DataGridTextColumn Binding="{ID}"/>
                <DataGridCheckBoxColumn Binding="{Accepted}"/>
            </DataGrid.Columns>
        </DataGrid>
    
    </UserControl.Resources>
    <Grid>
        <ContentControl Content="{StaticResource DataGrid1}" DataContext="{Binding MyTable}" Name="myContent"/}    
    </Grid>
    

    Y por codigo puede cambiarse el content

    myContent.Content = this.FindResource(“DataGrid2”);

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

Sidebar

Related Questions

I've got a DataGrid with 6 columns: ComboBox;ComboBox;CheckBox;CheckBox;CheckBox;TextBox I'm trying to populate this DataGrid
I am trying populate H3 with the sum of column E for rows that
I'm trying to setup a DataGrid that contains a column of combo boxes. The
I am trying to build a DataTable to populate a DataGrid in VB.NET. The
I trying to populate the dropdown list when page was loaded.But it is not
I am trying to populate a ListView ....but I cant add 2 string values
I am trying to populate a spinner, but am getting an error. Here is
I'm trying to use WPFToolkit's DataGrid control (and C#/.Net 3.5) to display a ComboBox
I am trying to nest one gridview within another, but I cannot get the
I have a list that I populate in the init of my viewmodel: ListOfEmployees

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.