开发工具是VS2005,项目是P PC2003移动项目!
问题:控件DataGrid的使用方法!
我把DataTable绑定在DataGrid上,然后用代码添加行列!
现在的问题是,运行后表格元素是禁止编辑的!什么方法可以编辑表格元素?
如果编辑不了,我想在表格上覆盖TextBox,获取表格的坐标,然后把TextBox覆盖在上面!求高手帮忙解决一下!
在界面上画一个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行
}
}
}
}