为什么我DATAGRIDVIEW里不能写入数据?

herott632482577 2010-09-16 01:36:50
把鼠标移到下个单元格上个单元格的值就没了?
public AddPlan()
{
InitializeComponent();
this.dataGridView2.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter;
dataGridView2.AllowUserToAddRows = true;
}
private void btn_tj_Click(object sender, EventArgs e)
{

int index2 = 0;
int index3 = 1;
int index4 = 2;
int index5 = 3;
int index6 = 4;
int index7 = 5;
int index8 = 6;
int index9 = 7;
string num = dataGridView2[index2, dataGridView2.SelectedCells[0].RowIndex].Value.ToString();
string name = dataGridView2[index3, dataGridView2.SelectedCells[0].RowIndex].Value.ToString();
string count = dataGridView2[index4, dataGridView2.SelectedCells[0].RowIndex].Value.ToString();
string model = dataGridView2[index5, dataGridView2.SelectedCells[0].RowIndex].Value.ToString();
string kwm = dataGridView2[index6, dataGridView2.SelectedCells[0].RowIndex].Value.ToString();
string gys = dataGridView2[index7, dataGridView2.SelectedCells[0].RowIndex].Value.ToString();
string bz = dataGridView2[index8, dataGridView2.SelectedCells[0].RowIndex].Value.ToString();
string people = dataGridView2[index9, dataGridView2.SelectedCells[0].RowIndex].Value.ToString();
string temp1 = string.Format("insert into T_Purchasing(T_Number,T_Name,T_Quantity,T_Model,T_DepotName,T_SupplierName,T_Remark,T_Principal,T_date) values('" + num + "','" + name + "'," + Int32.Parse(count) + ",'" + model + "','" + kwm + "','" + gys + "','" + bz + "','" + people + "')");
DCC.SqlDC.SDC.GetTable(temp1);
DialogResult result = MessageBox.Show("添加成功", "采购管理", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
if (result == DialogResult.OK)
{
this.Close();
}

}
private void dataGridView2_MouseDown(object sender, MouseEventArgs e)
{
dataGridView2.ContextMenuStrip = contextMenuStrip1;

}

private void 插入数据ToolStripMenuItem_Click(object sender, EventArgs e)
{
dataGridView2.ColumnCount = 8;//定义增加列的总数
dataGridView2.Columns[0].Name = "物料编号";
dataGridView2.Columns[1].Name = "所属物品";
dataGridView2.Columns[2].Name = "数量";
dataGridView2.Columns[3].Name = "1=成品库,2=部件库,3=零件库";
dataGridView2.Columns[4].Name = "供应商名称";
dataGridView2.Columns[5].Name = "备注";
dataGridView2.Columns[6].Name = "制表人";
dataGridView2.Columns[7].Name = "制表日期";
}
...全文
215 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
herott632482577 2010-09-17
  • 打赏
  • 举报
回复
4楼的添加会抱错啊
hinada99 2010-09-16
  • 打赏
  • 举报
回复
我也遇上了这个问题,顶下额
liyangyang621726 2010-09-16
  • 打赏
  • 举报
回复
this.DataGridView1.CurrentCell = this.DataGridView1.Rows[3].Cells[2];
this.DataGridView1.BeginEdit(True);

DataGridViewRow row = new DataGridViewRow();
row.Cells[0].Value =dt[""].ToString();
row.Cells[1].Value = dt[""].ToString();
this.dataGridView1.Rows.Add(row);
a312983516 2010-09-16
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 benyouyong 的回复:]
private void 插入数据ToolStripMenuItem_Click(object sender, EventArgs e)
{
dataGridView2.ColumnCount = 8;//定义增加列的总数
dataGridView2.Columns[0].Name = "物料编号";
dataGridView2.Columns[1].Name = "所……
[/Quote]
正解
wuyq11 2010-09-16
  • 打赏
  • 举报
回复
this.DataGridView1.CurrentCell = this.DataGridView1.Rows[3].Cells[2];
this.DataGridView1.BeginEdit(True);

DataGridViewRow row = new DataGridViewRow();
row.Cells[0].Value =dt[""].ToString();
row.Cells[1].Value = dt[""].ToString();
this.dataGridView1.Rows.Add(row);
benyouyong 2010-09-16
  • 打赏
  • 举报
回复
private void 插入数据ToolStripMenuItem_Click(object sender, EventArgs e)
{
dataGridView2.ColumnCount = 8;//定义增加列的总数
dataGridView2.Columns[0].Name = "物料编号";
dataGridView2.Columns[1].Name = "所属物品";
dataGridView2.Columns[2].Name = "数量";
dataGridView2.Columns[3].Name = "1=成品库,2=部件库,3=零件库";
dataGridView2.Columns[4].Name = "供应商名称";
dataGridView2.Columns[5].Name = "备注";
dataGridView2.Columns[6].Name = "制表人";
dataGridView2.Columns[7].Name = "制表日期";
}
没有增加..
这样增加列dataGridView2.Columns.Add("物料编号");
herott632482577 2010-09-16
  • 打赏
  • 举报
回复
谢谢继续顶高手呢~~
herott632482577 2010-09-16
  • 打赏
  • 举报
回复
没人么UP~~~

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧