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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:52:46+00:00 2026-05-22T19:52:46+00:00

public class Person { private int _Id; public int Id{get{return value;} set{_Id=value;}} private string

  • 0
public class Person

    {

    private int _Id;
    public int Id{get{return value;} set{_Id=value;}}

    private string _Code
    public  string Code{get{return _Code;} set {_Code=value;}}

    private string _Name;
    public string Name{get{return _Name;}set{_Name=value;}}

    } 

this is my model class

I have a two Combobox in my form.Combo1 and Combo2.
Combo1 DisplayMember Code ValueMember Id
Combo2 DisplayMember Name ValueMember Id

I want to that when I change the Code or Name another combobox edit value and display value change

  • 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-22T19:52:46+00:00Added an answer on May 22, 2026 at 7:52 pm

    I’d recommend several changes:

    First, you might want to break your person class out into two classes: Code and Person

    public class Person
    {
        public int Id { get; set; }
        public int CodeId { get; set; }
        public string Name { get; set; }
    }
    
    public class Code
    {
        public int Id { get; set; }
        public string CodeText { get; set; }
    }
    

    Then create a class that you’ll set to your view’s datacontext, normally called a viewmodel in the MVVM design pattern:

    public class Data : INotifyPropertyChanged
    {
        public List<Person> People { get; set; }
        public List<Code> Codes { get; set; }
    
        private Code _selectedCode;
        public Code SelectedCode
        {
            get
            {
                return _selectedCode;
            }
            set
            {
                _selectedCode = value;
                PropertyChanged(this, new PropertyChangedEventArgs("SelectedCode"));
                SelectedPeople = People.Where(p => p.CodeId == SelectedCode.Id).ToList();
            }
        }
    
        private List<Person> _selectedPeople;
        public List<Person> SelectedPeople
        {
            get
            {
                return _selectedPeople;
            }
            set
            {
                _selectedPeople = value;
                PropertyChanged(this, new PropertyChangedEventArgs("SelectedPeople"));
            }
        }
    
        public event PropertyChangedEventHandler PropertyChanged;
    }
    

    Notice that it implements INotifyPropertyChanged. This is crucial with binding in Silverlight. In the constructor of your MainPage.xaml.cs:

    Data data = new Data
        {
            Codes = new List<Code>(),// populate your codes
    
            People = new List<Person>() // populate your people, giving them correct codeids
        }
    
    this.DataContext = data;
    

    Now in your view’s XAMl:

    <ComboBox Height="23" HorizontalAlignment="Left" Margin="12,12,0,0" Name="comboBox1" VerticalAlignment="Top" Width="120" ItemsSource="{Binding Codes}" SelectedItem="{Binding SelectedCode, Mode=TwoWay}" DisplayMemberPath="CodeText" />
    <ComboBox Height="23" HorizontalAlignment="Left" Margin="12,54,0,0" Name="comboBox2" VerticalAlignment="Top" Width="120" ItemsSource="{Binding SelectedPeople}" DisplayMemberPath="Name" />
    

    Notice the first combobox binds to the Codes collection on the DataContext. The selectedItem property TWO-WAY binds to the SelectedCode property on the datacontext. When the user changes that selected item, the setter on the datacontext gets called. We updated the list of peopel to show, and raise the PropertyChanged event which notifies the view that it needs to update the people box.

    Of course, this would be much cleaner if you properly implemented the MVVM design pattern. I like to use the MVVM Light toolkit for this.

    I know that was long-winded, but I wanted to guide you down a correct path so you could use this knowledge on this project and in the future 🙂

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

Sidebar

Related Questions

package pkgPeople; import java.io.Serializable; import java.text.DecimalFormat; public class Person implements Serializable{ private String name;
public class People { // Code to create a random set of people omitted
import java.util.*; import org.directwebremoting.util.Logger; public class People { public People() { people = new
I have something like Person , and Address object( Person has an Address and
EDIT> i am at a dead end... so i can continue looking for the
I was hoping that I could map a flat datareader into a nested DTO.
I have an application written in Spring 3.0 hooked up using Hibernate to a
Recently I've started hearing about POJOs (Plain Old Java Objects). I googled it, but
Having read the documentation and many many articles I believe the following should work
Made a much simpler example, hopefully someone can follow this and help me Here

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.