日期:2014-05-18  浏览次数:20710 次

|M| DataGri在绑定的时候如何来定义他的字段明 我是学ASP.NET的突然做WinForm感觉很麻烦
C# code

DataSet ds=clientPrint.GetOrder(User.UserName,User.UserPass);
dgOrder.DataSource = ds.Tables[0].DefaultView;



像如果是WebForm的话我只要在DataGrid的模版中改就可以了
但是WinForm的我实在不知道在哪里改比如我有数据

User Pass Name
Admin 123 小张

我要绑定后为
用户名 密码 姓名
Admin 123 小张

而我现在绑定的话只能为上面的那种样式

谢谢

------解决方案--------------------
你用的是1.1?

好像有个columncollection的属性,在里面设
------解决方案--------------------
我用是的2.0的
VS2005
------解决方案--------------------
RE:找不到 columncollection 这个属性

还有比如数据库里面有一个字段为 0 1 我想在DataGrid中用CheckBox来表示要怎么表示啊

感觉WinForm的好麻烦啊 用WebForm就简单得多了
------解决方案--------------------
UP
------解决方案--------------------
UP大家帮帮
------解决方案--------------------
你可以手动建列,动态绑定
------解决方案--------------------
vs2005 应该用datagridview了
SqlConnection Conn = new SqlConnection();
Conn.ConnectionString = "server=(local);Database=test;uid=sa;pwd=test";
Conn.Open();
DataSet ds = new DataSet();
SqlDataAdapter DP = new SqlDataAdapter("select top 10 * from table", Conn);
DP.Fill(ds, "table");
DP.Dispose();
Conn.Close();
Conn.Dispose();
ds.Tables[0].DefaultView.AllowDelete = true;
dataGridView1.AutoGenerateColumns = false;
DataGridViewTextBoxColumn colName = new DataGridViewTextBoxColumn();
colName.Name = "PKID";
colName.HeaderText = "PKID";
colName.DataPropertyName = "PKID";
this.dataGridView1.Columns.Add(colName);

DataGridViewTextBoxColumn colName1 = new DataGridViewTextBoxColumn();
colName1.Name = "SALES";
colName1.HeaderText = "SALES";
colName1.DataPropertyName = "SALES";
this.dataGridView1.Columns.Add(colName1);

dataGridView1.DataSource = ds.Tables[0];//.DefaultView;//设置DataGrid的数据源