以编程方式添加新行 [英] add new row programmatically
问题描述
我有一个datagridview和两个按钮.现在我要做的是分别添加新的空白行和分别使用添加和删除按钮删除选定的行.
请帮助我
在此先感谢
查看以下代码:
要将新行添加到DataGridView中:
私有 无效 AddButton_Click(对象发件人,EventArgs e) { // 在DataGridView中添加新行 此 .dataGridView1.Rows.Add(" ," ," 七个", 八个") ; // 在DataGridView中的0位置添加新行 此 .dataGridView1.Rows.Insert( 0 ," 一个", 两个"," ," 四个"); }
要将新行添加到DataGridView中:
私有 void DeleteButton_Click(对象发件人,EventArgs e) { 此 .dataGridView1.Rows.RemoveAt(此 .dataGridView1.CurrentRow.Index); }
希望它会为您提供帮助. void deleteButton_Click(对象发件人,EventArgs e) { 尝试 { dataGridViewTrial.Rows.RemoveAt(dataGridViewTrial.CurrentRow.Index); sqlDataAdapter.Update(dataTable); } 捕获(异常exceptionObj) { MessageBox.Show(exceptionObj.Message.ToString()); } }
通过此链接,它可以正常工作
链接
i have a datagridview and two buttons. now what i have to do is i have to add new blank row and delete selected row using add and delete button respectively.
plz heplp me out
thanks in advance
Check Out the following Code :
To add New Row into DataGridView :
private void AddButton_Click(object sender, EventArgs e) { //To Add New Row in DataGridView this.dataGridView1.Rows.Add("five", "six", "seven", "eight"); //To Add New Row in DataGridView at 0 position this.dataGridView1.Rows.Insert(0, "one", "two", "three", "four"); }
To add New Row into DataGridView :
private void DeleteButton_Click(object sender, EventArgs e) { this.dataGridView1.Rows.RemoveAt(this.dataGridView1.CurrentRow.Index); }
Ihope it will help you.
private void deleteButton_Click(object sender, EventArgs e) { try { dataGridViewTrial.Rows.RemoveAt(dataGridViewTrial.CurrentRow.Index); sqlDataAdapter.Update(dataTable); } catch (Exception exceptionObj) { MessageBox.Show(exceptionObj.Message.ToString()); } }
can follow below link to add row in dataridview
click here[^]
Mark as solution if its solved your problem
Go thru this link,it works
Link
这篇关于以编程方式添加新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!