title: How do you get the index of a column by the column name in an IList?
body: <p>I apologize if this happens to be an easy question, but I'm new to coding.  I've been banging my head against a wall with this problem for several days now on and off and have done numerous internet searches, but I keep coming up empty handed.</p>
  
  <p>I have captured data from a database view into an IList. Because the data comes from a view and might (potentially) change the order of how columns appear should changes ever need to be made (columns added, etc), I want to programmatically pull the column's index from the IList via the column name.  </p>
  
  <p>This is easy enough to do with a gridview since it has a nice "HeaderRow" property that allows me to write a bit of code to loop through any row and pull the headerRow name, compare it to the name I'm looking for and then pull an incremented count number when I find it, and Voila!, I then have the index.</p>
  
  <p>The problem is, I'm trying to avoid having to copy data from a list that was already copied from the entity framework that was copied from the database itself into another container (gridview) in order to have to manipulate it.  It just seems like it's getting needlessly complex involving a gridview.</p>
  
  <p>So, if anyone can tell me if there's a useful property of the IList class that I can use to acquire the column index # via the column name, please let me know and many thanks!</p>
  
  <p>Edit:</p>
  
  <p>In response to nvoigt's comment "An IList does not know anything about columns."</p>
  
  <p>I'm sure it must have some idea, because when I step through the code and look at the first row data in the IList, it has the column names there ("AppAnswer", etc).  All I want is some way to look through them and determine (by property or by code) what index that column name sits at.  See photo for clarification.<br>
  I've had to link it here since my rep isn't high enough to post photos: <a href="https://www.dropbox.com/s/2xg3nduhqnzbl8n/ILisst.JPG" rel="nofollow">https://www.dropbox.com/s/2xg3nduhqnzbl8n/ILisst.JPG</a></p>
  
  <p>Also, this is the code that captures the data from the view and puts it into the list:</p>
  
  <pre><code>IList&lt;View_AppQnA_All&gt; list1 = useful.GetQuestionAnswerListForJobPosition(1);
  </code></pre>
  
  <hr>
  
  <pre><code>public IList&lt;View_AppQnA_All&gt; GetQuestionAnswerListForJobPosition(int jobID)
  {
      IList&lt;View_AppQnA_All&gt; QuestionAnswerList = new List&lt;View_AppQnA_All&gt;();
  
      IQueryable&lt;View_AppQnA_All&gt; view = Repository.Current.ObjectContext.
                  View_AppQnA_All.Where(Q =&gt; Q.AppQuestionForJobPosition == jobID);
      QuestionAnswerList = view.ToList&lt;View_AppQnA_All&gt;();
  
      return QuestionAnswerList;
  }
  </code></pre>
  
  <hr>
  
  <pre><code>#region Imports
  using System;
  using System.Drawing;
  using System.IO;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using DataAccess;
  #endregion
  
  namespace AOJobApplication
  {
      class Repository
      {
          #region Declarations
  
          private static Repository m_instance;
          private static AOApplicationContext CWEntities;
          // Lock synchronization object
          //private static object syncLock = new object();
          private static readonly object syncLock = new object();
  
          #endregion
  
          #region Properties
  
          /// &lt;summary&gt;
          /// Returns the one and only Repository
          /// &lt;/summary&gt;
          public static Repository Current
          {
              get
              {
                  if (m_instance == null)
                  {
                      lock (syncLock)
                      {
                          if (m_instance == null)
                          {
                              m_instance = new Repository();
                          }
                      }
                  }
  
                  return m_instance;
              }
          }
  
          #endregion
  
          /// &lt;summary&gt;
          /// Object context to get entity objects application void
          /// &lt;/summary&gt;
          public AOApplicationContext ObjectContext
          {
              get
              {
                  if (CWEntities != null)
                  {
                      return CWEntities;
                  }
                  else
                  {
                      CWEntities = new AOApplicationContext();
  
                      return CWEntities;
                  }
              }
          }
      }
  }
  </code></pre>