开发工具是VS2005,项目是P PC2003移动项目!
问题:控件DataGrid的使用方法!
用代码生成了几行表格!
现在的问题是,运行后表格里面的元素不能改变值!
怎么才能改变表格元素的值?
希望高手指点一下!
程序界面:
程序代码:
namespace DeviceApplication2
{
public partial class Form1 : Form
{
private DataTable namesTable= new DataTable("names");
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.dataGrid1.DataSource = namesTable;
DataColumn idColumn = new DataColumn();
idColumn.DataType = System.Type.GetType("System.Int32");
idColumn.ColumnName = "File";
idColumn.AutoIncrement = true;
namesTable.Columns.Add(idColumn);
DataColumn fNameColumn = new DataColumn();
fNameColumn.DataType = System.Type.GetType("System.String");
fNameColumn.ColumnName = "Name";
fNameColumn.DefaultValue = "num";
namesTable.Columns.Add(fNameColumn);
DataColumn numColumn = new DataColumn();
numColumn.DefaultValue = "num";
namesTable.Columns.Add(numColumn);
numColumn.DataType = System.Type.GetType("System.String");
numColumn.ColumnName = "Data";
}
private void button1_Click(object sender, EventArgs e)
{
for (a = 0; a < 3; a++)
{
namesTable.Rows.Add(namesTable.NewRow()); //添加3行
}
}
}
}