在datagridview中要选中一行数据修改或删除或添加的代码怎么写!
在datagridview的控件中选中一行修改或是删除,添加的代码怎么写?右键菜单的那个可以写出来。可是在控件中增加一行后(直接用鼠标点击后输入数据)然后自动添加到数据!怎么写这个代码请教那位易做图了谢谢了! --------------------编程问答-------------------- datagridview.Remove(object);
datagridview.RemoveAt(索引);
datagridview.Add(); --------------------编程问答--------------------
private void toolStripButton3_Click(object sender, EventArgs e)--------------------编程问答-------------------- 谢谢了我回去试哦!
{
try
{
if (dataGridView1.Focus())
{
if (MessageBox.Show("确定删除吗?", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
int i = dataGridView1.CurrentCell.RowIndex;
string uname = dataGridView1.Rows[i].Cells[0].Value.ToString();
string upnumber = dataGridView1.Rows[i].Cells[1].Value.ToString();
SqlConnection con = new SqlConnection(conString);
con.Open();
string sql = "delete from suser where uname= '" + uname + "' and upnumber='" + upnumber + "'";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.ExecuteNonQuery();
string sql1 = "select uname,upnumber from suser";
DataSet ds = new DataSet();
SqlDataAdapter mydadapter = new SqlDataAdapter(sql1, con);
mydadapter.Fill(ds, "list");
this.dataGridView1.DataSource = ds.Tables["list"];
con.Close();
}
}
else
{
MessageBox.Show("请选择数据");
}
}
catch { MessageBox.Show("请选择数据"); }
}
补充:.NET技术 , C#