Welcome to the Xceed Community | Help
Community Search  
More Search Options

How to use a ForeignKeyConfiguration to auto-detect run-time Enum for cell drop-down list of a Column?

Page 1 of 2 (21 items)   1 2 Next >
Sort Posts: Previous Next
  •  07-02-2009, 1:18 PM Post no. 22230

    How to use a ForeignKeyConfiguration to auto-detect run-time Enum for cell drop-down list of a Column?

    I have a DataGrid bound to a class where one of the properties is of a run-time Enum type created using EnumBuilder.  I wish to have the Column automatically detect the enumerators in the enum and display them in a drop-down box on the cell (a ComboBox).

    I understand that if the enum was defined at design-time, I can use the following XAML code to do this:

      <ObjectDataProvider x:Key="myEnumValues" MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
        <ObjectDataProvider.MethodParameters>
          <x:Type TypeName="local:MyClass+MyEnum" />
        </ObjectDataProvider.MethodParameters>
      </ObjectDataProvider>

      ...

      <xcdg:Column>
        <xcdg:Column.ForeignKeyConfiguration>
          <xcdg:ForeignKeyConfiguration ItemsSource="{Binding Source={StaticResource myEnumValues}}" />
        </xcdg:Column.ForeignKeyConfiguration>
      </xcdg:Column>


    However, how can I achieve the same when I have a property of Enum type in MyClass which I assign using the following code in MyClass constructor?:

      MyEnum = (Enum)Activator.CreateInstance(myEnumBuilder.CreateType());


    And yes, this does need to be a run-time Enum.  Any help greatly appreciated.  Thanks!


    Assistant Vice President, .NET Development
    Barclays Capital, UK
  •  07-03-2009, 12:36 PM Post no. 22259 in reply to 22230

    Re: How to use a ForeignKeyConfiguration to auto-detect run-time Enum for cell drop-down list of a Column?

    If the enum property is exposed, you can simply bind to it as such in the ForeignKeyConfiguration:

    <xcdg:Column.ForeignKeyConfiguration>

        <xcdg:ForeignKeyConfiguration ItemsSource="{Binding Path=OccupationValues}" />

    </xcdg:Column.ForeignKeyConfiguration>


    public string[] OccupationValues

    {

      get

      {

        return Enum.GetNames( typeof( Occupation ) );

      }


    Technical Writer/Technical Support Team Manager - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  07-03-2009, 1:11 PM Post no. 22261 in reply to 22259

    Re: How to use a ForeignKeyConfiguration to auto-detect run-time Enum for cell drop-down list of a Column?

    Jenny:
       <xcdg:ForeignKeyConfiguration ItemsSource="{Binding Path=OccupationValues}" />
    </xcdg:Column.ForeignKeyConfiguration>

    I wonder to which this Binding inside the  ForeignKeyConfigurationis relative to? The business object which forms the datarow?


    /\/\arkus.
  •  07-03-2009, 1:13 PM Post no. 22262 in reply to 22261

    Re: How to use a ForeignKeyConfiguration to auto-detect run-time Enum for cell drop-down list of a Column?

    The window's DataContext is set to itself in the ctor of the window; therefore, the binding refers to the OccupationValues property defined on the window.
    Technical Writer/Technical Support Team Manager - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  07-07-2009, 10:33 AM Post no. 22329 in reply to 22262

    Re: How to use a ForeignKeyConfiguration to auto-detect run-time Enum for cell drop-down list of a Column?

    I cannot get this working at all.

    This is my XAML:

    <Page x:Class="WpfTestProject.Page1"
        xmlns="
    http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="
    http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:xcdg="
    http://schemas.xceed.com/wpf/xaml/datagrid"
        xmlns:s="clr-namespace:System;assembly=mscorlib"
        Title="Page1">
      <Grid>
        <Grid.Resources>
          <xcdg:DataGridCollectionViewSource x:Key="MySource"
                                             Source="{Binding RelativeSource={RelativeSource AncestorType={x:Type Page}}, Path=MyData}"
                                             AutoCreateForeignKeyDescriptions="True">
          </xcdg:DataGridCollectionViewSource>
        </Grid.Resources>
        <xcdg:DataGridControl Name="grid"
                              EditTriggers="BeginEditCommand,ActivationGesture,ClickOnCurrentCell"
                              ItemsSource="{Binding Source={StaticResource MySource}}"
                              AutoCreateForeignKeyConfigurations="True">
          <xcdg:DataGridControl.Columns>
            <xcdg:Column FieldName="Prop1">
              <xcdg:Column.ForeignKeyConfiguration>
                <xcdg:ForeignKeyConfiguration ItemsSource="{Binding Path=AlertEvents}" />
              </xcdg:Column.ForeignKeyConfiguration>
            </xcdg:Column>
          </xcdg:DataGridControl.Columns>
        </xcdg:DataGridControl>
      </Grid>
    </Page>


    This is my code-behind:

    namespace WpfTestProject
    {
        public enum MyEnum
        {
            Enum1,
            Enum12
        }

        public partial class Page1 : Page
        {
            public Page1()
            {
                InitializeComponent();

            }

            public IEnumerable MyData
            {
                get
                {
                    List<MyClass> dataList = new List<MyClass>();
                    dataList.Add(new MyClass());
                    return dataList;
                }
            }

            public string[] AlertEvents
            {
                get
                {
                    return Enum.GetNames(typeof(MyEnum));
                }
            }
        }

        public class MyClass
        {
            public MyEnum Prop1
            {
                get
                {
                    return MyEnum.Enum1;
                }
                set
                {
                }
            }
        }
    }


    The combobox that shows in the DataGrid for the Prop1 field doesn't have any items in it. What am I doing wrong? Of course, once I have this working, I wish to make Prop1 into a run-time Enum created by EnumBuilder.

    Thanks for any help!
    Jason


    Assistant Vice President, .NET Development
    Barclays Capital, UK
  •  07-07-2009, 11:04 AM Post no. 22331 in reply to 22329

    Re: How to use a ForeignKeyConfiguration to auto-detect run-time Enum for cell drop-down list of a Column?

    I am thinking you probably have an error in your output window in regards to the AlertEvents property not being found. Change the binding to point to the Page and the values should appear in the combobox.
    Technical Writer/Technical Support Team Manager - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  07-07-2009, 11:28 AM Post no. 22333 in reply to 22331

    Re: How to use a ForeignKeyConfiguration to auto-detect run-time Enum for cell drop-down list of a Column?

    I have changed the ForeignKeyConfiguration to this:

    <xcdg:ForeignKeyConfiguration ItemsSource="{Binding RelativeSource={RelativeSource AncestorType={x:Type Page}}, Path=AlertEvents}" /> 

    However, this still doesn't seem to be finding it.  I guess I'm doing something blatantly wrong?...


    Assistant Vice President, .NET Development
    Barclays Capital, UK
  •  07-07-2009, 12:26 PM Post no. 22336 in reply to 22331

    Re: How to use a ForeignKeyConfiguration to auto-detect run-time Enum for cell drop-down list of a Column?

    Any ideas?  Am still struggling with this...
    Assistant Vice President, .NET Development
    Barclays Capital, UK
  •  07-07-2009, 12:33 PM Post no. 22337 in reply to 22336

    Re: How to use a ForeignKeyConfiguration to auto-detect run-time Enum for cell drop-down list of a Column?

    No errors in the output window? 

    Send me an application that demonstrates this behavior and I will investigate further.  


    Technical Writer/Technical Support Team Manager - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  07-07-2009, 12:40 PM Post no. 22338 in reply to 22337

    Re: How to use a ForeignKeyConfiguration to auto-detect run-time Enum for cell drop-down list of a Column?

    Yes, I get an error in the output window, but your solution you suggested didn't work:

    System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=AlertEvents; DataItem=null; target element is 'ForeignKeyConfiguration' (HashCode=6480969); target property is 'ItemsSource' (type 'IEnumerable')


    Assistant Vice President, .NET Development
    Barclays Capital, UK
  •  07-07-2009, 12:44 PM Post no. 22339 in reply to 22337

    Re: How to use a ForeignKeyConfiguration to auto-detect run-time Enum for cell drop-down list of a Column?

    Attachment: WpfExampleProj.zip
    I've attached an example of this problem occurring.
    Assistant Vice President, .NET Development
    Barclays Capital, UK
  •  07-07-2009, 12:53 PM Post no. 22340 in reply to 22339

    Re: How to use a ForeignKeyConfiguration to auto-detect run-time Enum for cell drop-down list of a Column?

    I ran the provided sample and changed the definition for the Prop1 property to the following:

    private MyEnum m_enum; 

        public MyEnum Prop1

        {

          get

          {

            return m_enum;

          }

          set

          {

            m_enum = value;

          }

        } 

     

    Even without changing the property definition, the combobox appeared with the appropriate values and there were no binding errors in the output window. Can you tell me the exact version of the control that you are using? 


    Technical Writer/Technical Support Team Manager - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  07-07-2009, 12:58 PM Post no. 22341 in reply to 22340

    Re: How to use a ForeignKeyConfiguration to auto-detect run-time Enum for cell drop-down list of a Column?

    Version 3.2.9279.15050.
    Assistant Vice President, .NET Development
    Barclays Capital, UK
  •  07-07-2009, 1:04 PM Post no. 22342 in reply to 22341

    Re: How to use a ForeignKeyConfiguration to auto-detect run-time Enum for cell drop-down list of a Column?

    Send me an email (belandj@xceed.com) and I will send you the latest service pack, which is not yet publicly available. Maybe that is the cause of the issue.
    Technical Writer/Technical Support Team Manager - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  07-07-2009, 2:07 PM Post no. 22344 in reply to 22342

    Re: How to use a ForeignKeyConfiguration to auto-detect run-time Enum for cell drop-down list of a Column?

    Close but no cigar.

    The updated version you sent me fixes the issue of the DataGrid auto-detecting the enumerators of the enum property type (thus the combobox is populated with values from the design-time enum), but it still doesn't read the values from AlertEvents, which is what I need in order to make the property a run-time Enum type.  In fact, I still get the same error in the 'Output' window and if I change the type of Prop1 to Enum instead of MyEnum, the combobox shows no items.


    Assistant Vice President, .NET Development
    Barclays Capital, UK
Page 1 of 2 (21 items)   1 2 Next >
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.