Variable Columns
Hi,
I am trying to build a grid which has variable number of columns and with the names of the columns being variable as well. For example , I'm trying to have a grid with stock symbols AAPL, MSFT , INTC as column names and also have rows with the same names. Can you tell me what is the best way to achieve this. I am able to create the grid by adding one column as instrument name and then adding each column corresponding to the instrument name. I'm not sure how to update this grid though or if there is a better way to go about creating this. All help will be appreciated.
Here is my code
List<Instrument.Models.Instrument> instList = Instrument.Models.InstrumentHelper.getInstance().GetOrderedListOfQuarterlies();
Header header = new Header();
header.Add(new Column("Instrument","Instrument",60,ContentAlignment.MiddleCenter));
int index = 0;
foreach (var inst in instList)
{
if (index == 15)
break;
header.Add(new Column(inst.instrumentName,inst.instrumentName,45,ContentAlignment.MiddleCenter));
MatrixModel mx = new MatrixModel();
mx.Instrument = inst.instrumentName;
this.grid.Rows.Add(mx);
index++;
}
this.grid.Headers.Add(header);
/* This does not work */
//this.grid.Rows[0]["GEM4"].Value = 10;
//this.grid.Rows[0]["GEU4"].Value = 20;
and here is my model class
public class MatrixModel
{
public string Instrument { get; set; }
public double[] values = new double[15];
}
Thanks,
Deepak
-
Dear Deepak,
The grid doesn’t display business data directly. When you add a business object to the grid, it wraps implicitly this object with corresponding implementation of the IDataAccessor interface.
Dapfor.Net framework provides many implementations of this interface (DataObjectAccessor for objects of custom classes, ListDataAccessor for objects implementing IList interface, DictionaryDataAccessor for objects, implementing IDictionary). That’s why you can use the grid as follows:
grid.Rows.Add(new MyCalss()) or
grid.Rows.Add(new string[]{‘toto’, ‘titi’})You can also write your own data accessor but in your case the best way is to use the UnboundValueAccessor instead of MatrixModel:
Row row = grid.Rows.Add(new UnboundValueAccessor());
row["GEM4"].Value = 10;
row["toto"].Value = "titi";Best regards,
Dapfor
0
Please sign in to leave a comment.
Comments
1 comment