datagridview中的insert-update [英] insert-update in datagridview
问题描述
亲爱的,
i有小表学生(id,name,last_name,地址)和带有datagridview的小屏幕iam试图插入和更新
i希望在datagrid中添加记录,然后用户在该记录中输入数据
这是我的代码,我不知道是否可能
dear all ,
i have small table student(id,name,last_name,address) and small screeen with datagridview iam trying to make insert and update
i want to add record in datagrid and then user enter data in that record
this my code , i do not know if it's possible or not
private void button1_Click(object sender, EventArgs e)
{
DataRow dr = dt.NewRow();
dr["student_id"] = Convert.ToInt32(textBox1.Text);
dr["student_name"] = textBox2.Text;
dr["student_last_name"] = textBox3.Text;
dr["address"] = textBox4.Text;
dt.Rows.Add(dr);
obj.addstudent(Convert.ToInt32(dr["student_id"].ToString()), dr["student_name"].ToString(), dr["student_last_name"].ToString(), dr["address"].ToString());
dataGridView1.DataSource = dt;
}
其他东西更新我希望在同一行中的所有单元格更新后不触发事件每个单元格的事件就像在asp(rowupdating)中发生的一样,这是我的代码:
other thing update i want event firing after all cells in the same row updated not firing the event for each cell separetly like what happen in asp (rowupdating) this is my code :
int x, y;
private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
{
x = dataGridView1.CurrentCellAddress.X;
y = dataGridView1.CurrentCellAddress.Y;
}
private void dataGridView1_CancelRowEdit(object sender, QuestionEventArgs e)
{
x = -1;
y = -1;
}
int id;
string name, lname, add;
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
string s = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
id=Convert.ToInt32( dataGridView1 .Rows[e.RowIndex ].Cells[0].Value.ToString());
name=dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
lname = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
add = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
}
private void btnupdate_Click(object sender, EventArgs e)
{
int done = obj.updat(id,name,lname,add);
}
感谢和问候
thanks and regards
推荐答案
请尝试这个链接 [ ]。
它在GridView.hope中具有CRUD功能,它可以帮助你:)
Please try this link[].
It has the CRUD functionality in GridView.hope it will help you :)
这篇关于datagridview中的insert-update的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!