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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:47:06+00:00 2026-06-14T01:47:06+00:00

I have two enums: public enum MyEnumA { OptionA1 = 1, OptionA2 = 2,

  • 0

I have two enums:

public enum MyEnumA
{
    OptionA1 = 1,
    OptionA2 = 2,
    OptionA3 = 3,
}

public enum MyEnumB
{
    OptionB1 = 1,
    OptionB2 = 2,
    OptionB3 = 3,
}

and a class containing both enums

public class AB
{
    public MyEnumA A { get; set; }
    public MyEnumB B { get; set; }
}

I want to have a matrix of checkboxes of both enums. The data is read from and saved to a List. This list is the actual junction table. For the time being I filled the list by hand:

    private List<AB> ABList = new List<AB>();

    ABList.Add(new AB { A = MyEnumA.OptionA2, B = MyEnumB.OptionB1 });
    ABList.Add(new AB { A = MyEnumA.OptionA3, B = MyEnumB.OptionB3 });

The matrix now should look like this:

            OptionA1 OptionA2 OptionA3
OptionB1                 X
OptionB2
OptionB3                          X

I have found a WinForm solution where everything is done in code-behind: http://social.msdn.microsoft.com/Forums/eu/winformsdatacontrols/thread/33fae605-902a-40e3-9bbb-60b77fc33b9b But can’t it be done in xaml with data binding?

  • 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-14T01:47:08+00:00Added an answer on June 14, 2026 at 1:47 am

    Thanks for your solution, Grafix. It is very nice. I thought it would be neater to place it in a Converter, so I did it like this:

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var abList = value as List<AB>;
    
            if (abList == null)
                return null;
    
            var retVal = Enum.GetValues(typeof (MyEnumB)).Cast<MyEnumB>().Select(
                    b =>
                    new ABViewModel()
                        {
                            Name = b,
                            OptionA1 = abList.Any(ab => ab.B == b && ab.A == MyEnumA.OptionA1),
                            OptionA2 = abList.Any(ab => ab.B == b && ab.A == MyEnumA.OptionA2),
                            OptionA3 = abList.Any(ab => ab.B == b && ab.A == MyEnumA.OptionA3)
                        }).ToList();
            return retVal;
        }
    

    And the DataGrid:

        <DataGrid Height="215" HorizontalAlignment="Left" Margin="91,12,0,0" Name="dataGrid1" 
                VerticalAlignment="Top" Width="299" 
                ItemsSource="{Binding ABList, Converter={StaticResource listToDataTableConverter}}"
                d:DataContext="{d:DesignData }" />
    

    And I set the DataContext like this:

        public MainWindow()
        {
            InitializeComponent();
    
            ABList.Add(new AB { A = MyEnumA.OptionA2, B = MyEnumB.OptionB1 });
            ABList.Add(new AB { A = MyEnumA.OptionA3, B = MyEnumB.OptionB3 });
    
            DataContext = this;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an example class containing two data points: public enum Sort { First,
public enum ObjectType { Country=0, Region=1, Province=2, City=3, Hotel=4 } I have two applications
I have one class that declares an enumeration type as: public enum HOME_LOAN_TERMS {FIFTEEN_YEAR,
Possible Duplicate: Adding enum type to a list I have an enum class: public
I have a bunch of different enums, such as... public enum MyEnum { [Description(Army
The following code: foo.h #include bar.h class foo{ public: enum my_enum_type { ONE, TWO,
I have an enum public enum Number { ONE(one), TWO(two), THREE(three), FOUR(four); } i
A strange thing, I have two enum sets: public enum ComponentActionTypes { Add =
I have two enums, in two packages. I could have 1000 enums, un 1000
In my application, I have two equivalent enum s. One lives in the DAL,

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.