0

I am new in programming. I have a question about data biding in WPF.

I have two double arrays and would like to bind them to datagrid with two columns like:

-double[] acce goes to a column in datagridview with a header of "Acceleration"

-double[] peri goes to a column in datagridview with a header of "Period"

I googled this issue but could not find out the right one. An example showing how will be greatly appreciated. Thanks,

2
  • 3
    You might consider making a "state class" that contains those values for each measurement. Then making a List or better an observable collection of the objects. Then bind them to a datagridview. I think trying to bind to an array of values may bring its own challenges. Commented Jan 7, 2014 at 17:24
  • It may be hard for me to imnplement this. The answer below works for me. Thanks for your help! Commented Jan 8, 2014 at 15:08

1 Answer 1

1

You can't do that; you have to bind to one object. You could create a a double[,] array (i.e. a 2D array) and copy acce into one column ([0, x]) and peri into the other ([1, x]) and bind to this new array:

double[,] combined = new double[2, acce.Length];
for (int i = 0; i < acce.Length; i++)
{
    combined[0, i] = acce[i];
    combined[1, i] = peri[i];
}

..and then bind to combined. Or you get more ambitious (and possibly learn some more) and create a class as @FelixCastor suggested.

PS the code above assumes that peri and acce have the same length.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.