title: add row to datagridview by checking child node check box of treeview
body: <p>I'm new to C# and am working on first project.</p>
  
  <p>I have a WINFORM that displays a treenode and a datagridview.  I want selected items from the treenode to go to the datagridview.  If I select the parent node of treenode all children go to datagridview but if I just expand the parent and select one of the children, nothing goes to datagrid.  (selection of a treenode fires a method to get attributes of the item from sql table and it is the attributes that go to the grid + node value)</p>
  
  <p>When parent is selected  'if (e.Node.Nodes.Count > 0)' is true.
  When parent isn't selected but child is 'if (e.Node.Nodes.Count > 0)' is false.</p>
  
  <p>So my question is what code do I need to find child nodes that are checked/unchecked?  </p>
  
  <p>Once I get correct code to find child node check, what code moves it to datagrid or delete from datagrid if child is unchecked?</p>
  
  <pre><code>   private void getChildNodesToGrid()
      {
          // get all child nodes add to dataGridView
          DataTable dt = getFieldsTable();
          dgvColumns.DataSource = dt;
          getAttributeSIDs();
      }
  
  private void tvFileMan_AfterCheck(object sender, TreeViewEventArgs e)
      {
          getFileAndColumns();
          if (e.Node.Nodes.Count &gt; 0)
          {
             this.CheckAllChildNodes(e.Node, e.Node.Checked);
              // Checked a file so get fields and check all fields except subfiles.
              // Use this event handler to process actions from check box click
              e.Node.Expand();
              foreach (TreeNode tn in e.Node.Nodes)
              {
                  if (tn.Nodes.Count.Equals(0))
                      tn.Checked = e.Node.Checked;
              }
              getChildNodesToGrid();
   }       
  </code></pre>
  
  <p>Thank you but I have all that already and I’m getting all nodes to grid.  The problem I’m having is limiting to checked child nodes from filNode.Nodes.  I’ve been playing with ‘if (fileNode.Checked)’ but is never true even though I can print it in immediate window </p>
  
  <pre><code>?fileNode.Nodes[2]
  {Text = "1  - CARD COLOR"}
      base: {Text = "1  - CARD COLOR"}
      BackColor: "{Name=0, ARGB=(0, 0, 0, 0)}"
      Bounds: {X = 76 Y = 176 Width = 92 Height = 16}
      Checked: true
  
  
  
  
  
    private DataTable getFieldsTable()
      {
          //original
          DataTable dt = new DataTable();
          dt.Columns.Add("ColumnName");
          dt.Columns.Add("FMFieldName");
  .
  .
  .
          dt.Columns.Add("PointsToFileNumber");
          TreeNode fileNode = tvFileMan.SelectedNode;
          foreach (TreeNode tn in fileNode.Nodes)
          {
              if (tn.Nodes.Count == 0)
              {   
                  if (fileNode.Checked)
                  {
                   DataRow dr = dt.NewRow();
  
                  dr["FMFieldName"] = tn.Text.Substring(tn.Text.IndexOf("  - ") + 4);
                  dr["FMFieldNumber"] = tn.Tag.ToString();
                  dr["FMFileNumber"] = tn.Parent.Tag.ToString();
                  dr["ColumnName"] = suggestName(tn.Text.Substring(tn.Text.IndexOf("  - ") + 4));
                  //added by TEA 9/3/14 to get PointsToFileNumber in TreeNode
                  if (dr["PointsToFileNumber"].ToString().Length &gt; 0)
                  {
                      dr["ColumnName"] = suggestName(tn.Text.Substring(tn.Text.IndexOf("  - ") + 4) + "txt");
                  }
                  dt.Rows.Add(dr);
                  }
              }
          }
          return dt;
  
      }
  </code></pre>