Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
558
FieldLayout Refresh
posted

I have a user control that allows the user of the application to select which users are allowed to purchase an amount of a set of products.  A grid then is populated with the list of users selected as columns and the products are each a row in that grid.  The problem that I have is that the WCF service contains the underlying object with a List of User objects so whenever I try and edit the amount for that user, the grid won't allow me to exit the cell editor.  I think this is due to the fact that the grid does not auto generate its fields.

Is there a way where I can set define the columns in real time and then refresh the columns displayed after a user hits a button?  Below is a simple example of the hack where I hard-code in the properties.

WPF:

<Window x:Class="XamTreeView.Window1"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        Title="XamTreeView" Height="600" Width="600"

        xmlns:local="clr-namespace:XamTreeView"

        xmlns:igDP="http://infragistics.com/DataPresenter">

    <Grid x:Name="gridContainer">

        <igDP:XamDataGrid x:Name="grd" GroupByAreaLocation="None" DataSource="{Binding Path=MyProductCollection}">

            <igDP:XamDataGrid.FieldLayoutSettings>

                <igDP:FieldLayoutSettings AutoGenerateFields="True" AllowRecordFixing="Top" />

            </igDP:XamDataGrid.FieldLayoutSettings>

        </igDP:XamDataGrid>

    </Grid>

</Window>

C#:

public partial class Window1 : Window

    {

        public MyContext Cntx { get; private set; }

 

        public Window1()

        {

            InitializeComponent();

            MyContext ctx = new MyContext();

            ctx.Initialize();

            this.Cntx = ctx;

 

            this.gridContainer.DataContext = Cntx;

        }

    }

 

    public class MySimpleProduct

    {

        public string ProductName { get; set; }

 

        // These should come from a dictionary<String, double>...

        public double AdamBought { get; set; }

        public double BobBought { get; set; }

 

        public MySimpleProduct(string productName, double adamBought, double bobBought)

        {

            this.ProductName = productName;

            this.AdamBought = adamBought;

            this.BobBought = bobBought;

        }

    }

 

    public class MyContext

    {

        public List<MySimpleProduct> MyProductCollection { get; set; }

 

        public void Initialize()

        {

            this.MyProductCollection = new List<MySimpleProduct>();

            this.MyProductCollection.Add(new MySimpleProduct("Toys", 100, 10));

            this.MyProductCollection.Add(new MySimpleProduct("Houses", 90, 0));

        }

    }