茶馆

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

原来Blog上面的,抛弃有点可惜,贴过来

[datagrid]
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows;
using System.Windows.Forms;
using System.Data;

namespace DgHeader
{
    
public class FormNoVS:Form
    
{
        
private DataGrid dg1;
        
public FormNoVS()
        
{
            
this.Size = new Size(800600);
            DataTable table 
= new DataTable();
            table.Columns.Add(
"name");
            table.Columns.Add(
"age");
            DataRow row 
= table.NewRow();
            row[
"name"= "Test";
            row[
"age"= 13;
            table.Rows.Add(row);

            dg1 
= new DataGrid();
            
this.Controls.Add(dg1);
            dg1.Location 
= new Point(100,50);
            dg1.Size 
= new Size(400200);
            dg1.Name 
= "dg1";
            dg1.ColumnHeadersVisible 
= true;
            dg1.DataSource 
= table;
            DataGridTableStyle style 
= new DataGridTableStyle();
            DataGridTextBoxColumn headerName 
= new DataGridTextBoxColumn();
            headerName.HeaderText 
= "姓名";
            headerName.MappingName 
= "name";
            headerName.Width 
= 100;
            style.GridColumnStyles.AddRange(
new DataGridColumnStyle[] { headerName });
            dg1.TableStyles.AddRange(
new DataGridTableStyle[] { style });
        }

    }

}



[datagridview]
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows;
using System.Windows.Forms;
using System.Data;

namespace DgHeader
{
    
public class FormNoVS:Form
    
{
        
private DataGridView dgv1;
        
public FormNoVS()
        
{
            
this.Size = new Size(800600);

            DataTable table 
= new DataTable();
            table.Columns.Add(
"name");
            table.Columns.Add(
"age");
            DataRow row 
= table.NewRow();
            row[
"name"= "Test";
            row[
"age"= 13;
            table.Rows.Add(row);

            dgv1 
= new DataGridView();
            dgv1.Location 
= new Point(10,10);
            dgv1.Size 
= new Size(400200);
            
this.Controls.Add(dgv1);
            dgv1.DataSource 
= table;
            dgv1.AutoGenerateColumns 
=true;
            dgv1.Columns[
0].HeaderText = "姓名";
        }

    }

}
posted on 2005-12-09 23:02  laue  阅读(5012)  评论(0)    收藏  举报