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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:47:48+00:00 2026-05-30T10:47:48+00:00

I have a WPF containing a dynamically created DataGridComboBoxColumn this has a comboBox that

  • 0

I have a WPF containing a dynamically created DataGridComboBoxColumn this has a comboBox that I can change the value in any row. The table also contains a checkbox in another column, if I change this it calls a method each time a row is changed, I want the same result when I change the value in the combobox

I have a List of my Rum objects that for this purpose have three methods

public int rumStyle { get; set; }
public string rumStyleDesc { get; set; } // string representation  of ruymStyle
public bool rumIsValid { get; set; }

This checkbox part works

DataGridTemplateColumn textColumnValid = new DataGridTemplateColumn();
textColumnValid.Header = headerRumIsValid;
FrameworkElementFactory checkBoxFactory = new FrameworkElementFactory(typeof(CheckBox));
Binding rumIsValidBinding = new Binding("rumIsValid");
checkBoxFactory.SetValue(CheckBox.IsCheckedProperty, rumIsValidBinding);
checkBoxFactory.AddHandler(CheckBox.ClickEvent, new RoutedEventHandler(LostFocus));
DataTemplate rumIsdValidTemplate = new DataTemplate();
rumIsdValidTemplate.VisualTree = checkBoxFactory;
textColumnValid.CellTemplate = rumIsdValidTemplate;
_dgData.Columns.Add(textColumnValid);

This part does display a combobox in each row but I want it to call the LostFocus (or another method) when the selection is changed.

DataGridComboBoxColumn comb = new DataGridComboBoxColumn();
comb.Header = headerRumStyle;
comb.SelectedValueBinding = new Binding("rumStyleDesc");
comb.ItemsSource = _rumStyles.getRumStyleNames();
FrameworkElementFactory comboFactory = new FrameworkElementFactory(typeof(ComboBoxItem));
comboFactory.SetValue(ComboBox.SelectedItemProperty, new Binding("rumStyleDesc"));
comboFactory.AddHandler(ComboBox.SelectionChangedEvent, 
new SelectionChangedEventHandler(comboBox1_SelectionChanged));
DataTemplate comboboxTemplate = new DataTemplate();
comboboxTemplate.VisualTree = buttonFactory;
// How do I do this part 
// comb.CellTemplate = comboboxTemplate;
_dgData.Columns.Add(comb);

A second but less important question is can I display the rumStlyeDesc in the combobox but read back the rumstyleId somehow.

  • 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-30T10:47:49+00:00Added an answer on May 30, 2026 at 10:47 am

    Eventually found how to do it.

    Firstly I added the list of RumStyles to each of my rums with a method to get the style names as a List

    public RumStyles rumStyles { get; set; }
    public List<string> rumStlyesList{ get {return rumStyles.getRumStyleNames();}}
    

    I then came up with the following code to build the ComboBox in a DataGridTemplateColumn not a DataGridComboBoxColumn

    DataGridTemplateColumn changeRumStyleColumn = new DataGridTemplateColumn();
    changeRumStyleColumn.Header = headerRumStyle;
    FrameworkElementFactory styleComboFactory = 
        new FrameworkElementFactory(typeof(ComboBox));
    Binding selectedStyle = new Binding("rumStyleDesc");
    styleComboFactory.SetBinding(ComboBox.ItemsSourceProperty,
        new Binding("rumStlyesList"));
    styleComboFactory.SetBinding(ComboBox.SelectedItemProperty, new Binding("rumStyleDesc"));
    styleComboFactory.SetValue(ComboBox.SelectedItemProperty, selectedStyle);
    styleComboFactory.AddHandler(ComboBox.SelectionChangedEvent, 
    new SelectionChangedEventHandler(comboBox1_SelectionChanged));
    DataTemplate rumStyleTemplate = new DataTemplate();
    rumStyleTemplate.VisualTree = styleComboFactory;
    changeRumStyleColumn.CellTemplate = rumStyleTemplate;
    _dgData.Columns.Add(changeRumStyleColumn);
    

    There is one issue remaining and that may be fixed by changing the SelectionChangedEvent that is that when ever the row is first displayed the comboBox1_SelectionChanged is called.

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

Sidebar

Related Questions

I have a Windows Forms app, that has a single ElementHost containing a WPF
I have WPF window containing a listview that has it's itemsource set to a
I have wpf UserControl containing a combobox and a textbox in a row. Currently
I have a WPF application that is made up of a window containing a
I am working in C# and VS2008. I have a WPF application containing a
I have WPF Span that is used as a source to a TextBlock. I
I have WPF Form which has many buttons with the same code. Appearance of
I have a WPF Window which has a among other controls hosts a Frame.
I have a WPF ListView control containing a number of RadioButton controls using data
I have just changed my WPF application from .Net3.5 to .Net4. Doing this caused

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.