title: Moving word tables into datagridview in windows c#
body: <p>I have an application where the data is stored in word tables. I want to put the contents of the table into gridview. Is it possible to do so. below is a part of the code</p>
  
  <pre><code>private void FillDocumentInfo(Word._Document reportDoc, string heading, Hashtable documentInfo)
  {
      object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
      object oMissing = System.Reflection.Missing.Value;
  
      Word.Paragraph oPara;
      object oRng = reportDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
      oPara = reportDoc.Content.Paragraphs.Add(ref oRng);
      oPara.Range.InsertParagraphBefore();
      oPara.Range.Font.Size = 20;
      oPara.Range.Text = heading;
      oPara.Range.Font.Bold = 1;
  
      oPara.Range.InsertParagraphAfter();
      Word.Range wrdRng = reportDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
      Word.Table oTable;
      wrdRng = reportDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
      oTable = reportDoc.Tables.Add(wrdRng, documentInfo.Count, 2, ref oMissing, ref oMissing);
      oTable.AutoFitBehavior(Word.WdAutoFitBehavior.wdAutoFitContent);
      oTable.Range.ParagraphFormat.SpaceAfter = 6;
  
      IDictionaryEnumerator _enumerator = documentInfo.GetEnumerator();
      int r = 1, c = 1;
      while (_enumerator.MoveNext())
      {
          oTable.Rows[r].Range.Font.Bold = 0;
          oTable.Rows[r].Range.Font.Italic = 1;
          oTable.Cell(r, c++).Range.Text = _enumerator.Key.ToString();
          oTable.Cell(r++, c--).Range.Text = _enumerator.Value.ToString();
  
          List&lt;string&gt; cellValues = new List&lt;string&gt;();
  
          string cellContents = _enumerator.Key.ToString();
          string cellcont = _enumerator.Value.ToString();
          // add the cell contents to the array, but remove the strange termination character on the end of the data
          cellValues.Add(cellContents.Remove(cellContents.Length - 1));
          cellValues.Add(cellcont.Remove(cellcont.Length - 1));
  
          AddWordTableRow(cellValues);
      }                                    
      documentInfo.Clear();
  }
  
  public void AddWordTableRow1(string name, string address)
  {
      dataGridView1.Rows.Add(new string[] { name, address});
  }
  
  public void AddWordTableRow(List&lt;string&gt; cellValues)
  {
      DataGridViewRow dr = new DataGridViewRow();
      dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; 
      AddWordTableRow1(cellValues[0], cellValues[1]);
  }
  </code></pre>
  
  <p>Here am getting cross thread operation exception</p>