0

I am trying to build a DataMatrix in WPF which needs to have row and column headers, dynamically generated rows and columns and commands linked to each cell. Due to this, I am unable to use a DataGrid. There are a few solutions like Josh Smith's Data Matrix and this. I am leaning towards the former as I feel I might be able to achieve what I want more elegantly with that.

Unlike his example(Demo1), I don't know the names or the number of rows/columns before hand and am stuck in generating a KeyValuePair for the dictionary. Below is some pseudocode comparing his implementation to mine. I would appreciate if someone pointed me in the right direction. His code

class Dataclass:
{
string columnname;
int row1data;
int row2data;
}

class MatrixClass: MatrixBase<string DataClass>
{
Dictionary<string Callback> rowvaluemap;
delegate object Callback(Dataclass data);

AddMappings()
{
rowvaluemap.Add("row1name", data=>data.row1data.ToString);
}
}

My implementation ??(code) indicates the part I'm unsure about

class MyDataclass:
    {
    string columnname;
    string[] rownames;
    int[] rowdata;
    }
class MyMatrixClass: MatrixBase<string MyDataClass>
    {
    Dictionary<??(Callback1), ??(Callback2)> rowvaluemap;

    delegate object Callback(MyDataclass data);
    delegate object Callback2(MyDataclass data);
    AddMappings()
    {
    rowvaluemap.Add(??(data=>data.rownames.ToString), ??(data=>data.rowdata.ToString));
    }
    }

I realize that doing it this way would most likely give me one IEnumerable key & one IEnumerable Value, but I'm completely lost on this one.I would appreciate your help or any alternative suggestions to achieve my target. Thanks

Community
  • 1
  • 1
Suhas Anjaria
  • 120
  • 1
  • 11
  • [How do I bind a WPF DataGrid to a variable number of columns?](http://stackoverflow.com/questions/320089/how-do-i-bind-a-wpf-datagrid-to-a-variable-number-of-columns), [How do I dynamically generate columns in a WPF DataGrid?](http://stackoverflow.com/questions/1983033/how-do-i-dynamically-generate-columns-in-a-wpf-datagrid), [WPF MvvM DataGrid Dynamic Columns](http://stackoverflow.com/questions/3065758/wpf-mvvm-datagrid-dynamic-columns). – Sheridan Jul 08 '15 at 07:53
  • @Sheridan: +1 Thanks! I looked through them before but was fixated on Josh's implementation. The first link you posted seems like an elegant enough solution to what I am doing and worked like a charm once i figured out how to make the ExpandoObject. I have a couple of followup questions(related to INotifyPropertyChanged & RowTemplate generation) . Should I edit this question or post that as a separate question by itself? – Suhas Anjaria Jul 09 '15 at 04:18

0 Answers0