Hi
I have 2 lists..
The first contains rows with mapping values inlcuding column name, xcord, ycord
The second contains the data I need to map..
I need to get the value in each row using the column name from the first row..
for example
List<SheetMappings> smaps = new <SheetMappings>();
Foreach(maplist m in mlist)
{
SheetMappings newMap = new SheetMappings();
foreach(vallist v in vlist)
{
newMap.Value = v.{m.ColumnName};
newMap.xCord = m.xCord;
newMap.yCord = m.yCord;
}
smaps.Add(newMap);
}
Any assitance appreciated
Cheers
Graham
Software/Hardware used:
visual studio 2010 c#
ASKED:
March 20, 2012 10:53 PM
UPDATED:
March 21, 2012 12:35 PM
Please be a little more specific.
What exactly do you need help with ?
Does your code work (at least partially) ? Does it give errors ?
Where is the mlist and vlist declaration ?
ok…
what I am trying to do is get values from a table row to map the x,y cells of an excel sheet..
the first list contains the rows with Column_Name, yCord and yCord values (maplist)
The second list contains rows with the actual values… the number of columns varies depending on which table I am processing…
So, I loop through the 1st list and get a row from the spreadmaps,,, I then go through the second list and want to get the value from each row based on the column_name supplied from maplist…
so v.’column_name’… ie v.date or v.openingBalance or v.closing balance.. where the column is based on what is supplied by the column_name string from spreadmaps
I need to be ‘dynamic’ here as each sheet on the ‘spread’ control ca be based on a different table and therefore column_names
Hope this makes sense..
at the moment I have to ‘hard code’ via a switch statement for each table and column names.. this if course will not work when the users add other tables… here is sample:
List<SpreadMappings> spreadMapping = new List<SpreadMappings>(); foreach (var m in mappings) { foreach (var v in hvalues) { SpreadMappings map = new SpreadMappings(); value = v.GetType().GetProperty(m.ColumnName).GetValue(v, null); switch (m.ColumnName) { case "DocHeading": map.ColumnX = m.ColumnX; map.ColumnY = m.ColumnY; map.ColumnValue = v.DocHeading; map.ColumnName = m.ColumnName; map.ColumnId = v.Id; map.ColumnSheetName = sheetName; spreadMapping.Add(map); break; case "OrderCarryOverUnit1": map.ColumnX = m.ColumnX; map.ColumnY = m.ColumnY; map.ColumnValue = v.OrderCarryOverUnit1; map.ColumnName = m.ColumnName; map.ColumnId = v.Id; map.ColumnSheetName = sheetName; spreadMapping.Add(map); break;Cheers
the line value = v.GetType().GetProperty(m.ColumnName).GetValue(v, null);
was were I was ‘experimenting’