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
565
Dynamically added columns - header shows up, values don't
posted

I've got  a XamDataGrid where I'm adding columns dynamically.  The columns add themselves directly, and the headers are correct, but the data cell values are blank.  I can't figure out how to get the binding right.

I've read through quite a few other similar threads, but none of them seemed to fit my situation right.

Code snippets are below.  I tried to cut out superfluous detail; apologies for any artifacts from those edits.

The interesting part is the AddColumn() method at the end.  I first tried using a Field type instead of the UnboundField, but I couldn't find an appropriate method or property to set binding.  Following an example in another thread, I tried the UnboundField as you can see below, but it's not right.  (I hope it's not something silly like an incomplete BindingPath, but it's possible.)

Any help would be much appreciated.

 

WPF Code:

<igDP:XamDataGrid.FieldLayouts>
    <igDP:FieldLayout>
        <igDP:FieldLayout.Fields />
    </igDP:FieldLayout>
</igDP:XamDataGrid.FieldLayouts>

Code-Behind:

// storage class for each row
public class QBRow
{
    public List<string> Items { get; private set; }

    public QBRow(string rowHeader)
    {
        Items = new List<string>();
    }
}

// ctor for the window that contains the XamDataGrid
public QuotesBoard()
{
    Rows = new BindingList<QBRow>();

    InitializeComponent();
    grid.DataSource = Rows; //grid is the XamDataGrid, of course
}

// method that adds the column
private void AddColumn(string r0, string r1, string r2)
{
    Rows[0].Items.Add(r1);
    Rows[1].Items.Add(r2);
    Rows[2].Items.Add(r3);

    int index = Rows[0].Items.Count - 1;

    Infragistics.Windows.DataPresenter.UnboundField f =
        new Infragistics.Windows.DataPresenter.UnboundField();
    f.Name = "newCol_"+index.ToString();
    f.DataType = typeof(string);
    f.BindingPath = new PropertyPath("Items["+index+"].Value");
    //Also attempted: "Items[0].Value"
    grid.FieldLayouts[0].Fields.Add(f);
}