在ListView控件中实现修改功能

时间:2023-03-09 05:56:33
在ListView控件中实现修改功能

实现效果:

  在ListView控件中实现修改功能

知识运用:

  ListView控件的LabelEdit属性  //指示用户是否可以编辑控件中数据项的标签

  public bool LabelEdit{get;set;}

实现代码:

        private void listView1_AfterLabelEdit(object sender, LabelEditEventArgs e)
{
SqlConnection s_con = new SqlConnection(P_connection);
if (s_con.State == ConnectionState.Closed) {
s_con.Open();
}
if (e.Label != null && e.Label != "") {
string RefreshString="update fruit set 名称='"+e.Label+"'where 编号="+(e.Item+1).ToString();
SqlCommand s_com = new SqlCommand(RefreshString,s_con);
s_com.ExecuteNonQuery();
s_con.Close();
MessageBox.Show("数据修改成功","提示信息",
MessageBoxButtons.OK,MessageBoxIcon.Asterisk);
}
}

相关文章