Data Binding with WPF DataGrid - VB.NET

I am working on a display that needs to show an array of objects in a DataGrid (WPF). Each object has two properties, one is a simple number (Base) the other is an array of numbers (Data). I have created some test data as a small array of these objects and bound it to the ItemsSource property of my DataGrid. I get the first column displayed (the Base value) but I cannot figure out how to get each entry from the Data array into a column.

Ultimately the Data columns will need to be edited but this first step has me stumped.
Thanks in advance for any input,
Sid
Sid PriceSoftware Systems Architect/DesignerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Randy DownsOWNERCommented:
Maybe this will help.

public class TestRow
{
    private bool[] _values = new bool[10];
    public bool[] Values
    {
        get { return _values; }
        set { _values = value; }
    }

    public TestRow(int seed)
    {
        Random random = new Random(seed);
        for (int i = 0; i < Values.Length; i++)
        {
            Values[i] = random.Next(0, 2) == 0 ? false : true;
        }
    }
}

Open in new window


DataGrid grid = new DataGrid();
var data = new TestRow[] { new TestRow(1), new TestRow(2), new TestRow(3) };
grid.AutoGenerateColumns = false;
for (int i = 0; i < data[0].Values.Length; i++)
{
    var col = new DataGridCheckBoxColumn();
    //Here i bind to the various indices.
    var binding = new Binding("Values[" + i + "]");
    col.Binding = binding;
    grid.Columns.Add(col);
}
grid.ItemsSource = data;

Open in new window


using data[0].Values.Length when creating the columns could obviously throw an exception if the data collection is empty.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sid PriceSoftware Systems Architect/DesignerAuthor Commented:
Thank you Randy that was most helpful. While it doesn't address my issue fully I can re-arrange my data to use your solution.
Many thanks,
Sid
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.