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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:18:43+00:00 2026-06-19T03:18:43+00:00

I have 2 comboboxes. If i select a Activity in the 1st one, the

  • 0

I have 2 comboboxes. If i select a Activity in the 1st one, the related sub activities should be displayed in the second combobox.
The code looks fine as per MVVM style but when i select an activity on 1st one, the related subactivities in the 2nd combobox are not synched.
Here is my code:
View

<Window x:Class="TestDGCombosBinding.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:TestDGCombosBinding"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <Grid.Resources>
        <ObjectDataProvider x:Key="ActivitiesDataProvider" ObjectType="{x:Type local:Activities}" MethodName="GetActivities"/>
        <local:DebugConverter x:Key="DebugConverter" />
    </Grid.Resources>
    <DataGrid 
        Grid.Row="1" Grid.Column="1" 
                 AutoGenerateColumns="False"                     
                 SelectionUnit="CellOrRowHeader"
                 SelectionMode="Single"
                 IsSynchronizedWithCurrentItem="True" 
                 RowBackground="White" 
                 AlternatingRowBackground="LightGray"                                          
                 AlternationCount="2" Name="dataGrid1" CurrentCellChanged="dataGrid1_CurrentCellChanged">
        <DataGrid.BindingGroup>
            <BindingGroup />
        </DataGrid.BindingGroup>
        <DataGrid.Resources>

        </DataGrid.Resources>

        <DataGrid.Columns>
            <DataGridTemplateColumn Header="Activities Custom" CanUserSort="True">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <ComboBox Text="{Binding CurrentActivity}"                                       
                                    SelectedValuePath="ActivityID"                                        
                                    DisplayMemberPath="ActivityName"
                                    ItemsSource="{Binding Source={StaticResource ActivitiesDataProvider}}"/>
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>
            <DataGridTemplateColumn Header="SubActivities Custom" >
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <ComboBox Text="{Binding CurrentSubActivity}"                                       
                                    SelectedValuePath="SubActivityID"                                      
                                    DisplayMemberPath="SubActivityname"
                                    ItemsSource="{Binding Path=SubActivitiesOfCurrentActivity}"/>
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>

        </DataGrid.Columns>
    </DataGrid>
</Grid>


Model

public class Activities
{
    public DataView GetActivities()
    {
        return ActivitiesAccess.GetAllActivities();
    }
}

ViewModel

public class ActivitiesViewModel : INotifyPropertyChanged
{
    public ActivitiesViewModel()
    { }
    private int currentActivity;

    public int CurrentActivity
    {
        get { return currentActivity; }
        set { 
                currentActivity = value;
                SubActivitiesOfCurrentActivity = ActivitiesAccess.GetAllSubActivitiesinActivity(currentActivity);
                OnPropertyChanged("CurrentActivity");
            }
    }

    private DataView subActivitiesOfCurrentActivity;

    public DataView SubActivitiesOfCurrentActivity
    {
        get {return subActivitiesOfCurrentActivity; }
        set
        {
            subActivitiesOfCurrentActivity = value;
            OnPropertyChanged("SubActivitiesOfCurrentActivity");
        }
    }

    private int currentSubActivity;

    public int CurrentSubActivity
    {
        get { return currentSubActivity; }
        set
        {
            currentSubActivity = value;
            OnPropertyChanged("CurrentSubActivity");
            }
    }

    public event PropertyChangedEventHandler PropertyChanged;

    private void OnPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

When i debug the code when i select an activity from the 1st drop down, the CurrentActivity property value is always 0 which im not sure why.
This value should be equal to the ActivityID of the selected activity.
I searched alot to get help but i couldnt find anything.
I will be very happy if someone could specify any problem in the code.

  • 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-19T03:18:44+00:00Added an answer on June 19, 2026 at 3:18 am

    I resolved my issue.
    When An Activity is Changed, the related Sub-Activities should be notified of the change.
    But when the Sub-Activity is changed there is no need to notify the Activity.

    I just commented OnPropertyChanged() call in CurrentSubActivity property.
    Here is the code

    private int currentSubActivity;
    
        public int CurrentSubActivity
        {
            get { return currentSubActivity; }
            set
            {
                //OnPropertyChanged("CurrentSubActivity");
                this.currentSubActivity = value;
    
            }
        }
    

    I hope this helps someone out there too 🙂

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

Sidebar

Related Questions

I have two related ComboBoxes ( continents, and countries ). When the continents ComboBox
I have 2 comboboxes. The first selects a category, the second selects the sub
I have two comboBoxes, one is CountryCombo and second is StateCombo. What I want
I have two comboboxes. First combobox is for selecting the manager and the second
I have two comboBoxes . In first I select Brand, in the second I
I need to build a form where I have 2 comboBoxes . Select country
I have a combobox in winforms, which, depending on what you select, determines what's
I have an Activity object with many properties. One of them is as follows:
I have two g:select comboboxes that I want to add to the multiple select
I have 2 comboboxes, combo1 and combo2, If I select any value in combo1,

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.