C#DataGridView手动创建数据源

        DataGridView dgv;

        DataTable dt;
        DataRow dr;

       DataTable   creatDataSource()
        {
            dt = new DataTable();
            dt.Columns .Add(new DataColumn("一级节点",typeof (string)));
            dt.Columns.Add(new DataColumn("二级节点", typeof (string )));
            dt.Columns .Add (new DataColumn ("三级节点",typeof (string )));
           
            return dt;
        }

      dgv.DataSource = creatDataSource();

       dr[0] = atrribute.StringValue;
        dr[1] = atrribute.StringValue;
        dr[2] = atrribute.StringValue;         

        dt.Rows.Add(dr);

你可能感兴趣的:(C#DataGridView手动创建数据源)