Get value from column using a column name string c#
<p>I have 2 lists..</p>

<p>The first contains rows with mapping values inlcuding column name, xcord, ycord</p>

<p>The second contains the data I need to map.. </p>

<p>I need to get the value in each row using the column name from the first row..</p>

<p>for example</p>

<pre><code>List&lt;SheetMappings&gt; smaps = new List&lt;SheetMappings&gt;();

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);
}
</code></pre>

<p>Any assitance appreciated</p>

<p>Cheers</p>

<p>Graham</p>

<p>EDIT:</p>

<pre><code>List&lt;SpreadMappings&gt; spreadMapping = new List&lt;SpreadMappings&gt;(); 
foreach (var m in mappings) 
{ 
    foreach (var v in hvalues) 
    { 
        SpreadMappings map = new SpreadMappings(); 
        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;
</code></pre>
