DataGrid是用来数据绑定的,最好的绑定源自然是DataSet.所以如果你要实现对DataGrid添加数据,先要对DataSet添加数据。
示例:
DataRow row=ds.Tables["Agent"].NewRow(); //ds为你初始化后的DataSet
row["AgentName"]="Agent1";
row["Description"]="It's an agent";
ds.Tables["Agent"].Rows.Add(row);
ds.AcceptChanges();
dgrd1.DataSource=ds.Tables["Agent"].DefaultView;
dgrd1.DataBind();