C# listview 修改数据,右击删除数据?
C#中listview控件里已经显示了我所需要的数据。但是我现在想右击可以编辑某一条记录,或者删除某条记录,问怎么搞定。朋友们,请帮个忙!谢谢!有类似的代码贴一下!...
C#中listview控件里已经显示了我所需要的数据。但是我现在想右击可以编辑某一条记录,或者删除某条记录,问怎么搞定。朋友们,请帮个忙!谢谢!有类似的代码贴一下!
展开
展开全部
使用DataBindings 绑定 修改后会直接修改列对象的值
this.txtProdCheck.DataBindings.Clear();
this.txtProdPrice.DataBindings.Clear();
this.txtProdRequire.DataBindings.Clear();
this.txtProdWorktime.DataBindings.Clear();
class o = lbxSchName.SelectedItem as class;
if (o != null)
{
this.txtProdCheck.DataBindings.Add("Text", o, "ProdCheck");//ProdCheck为对象class的字段
this.txtProdPrice.DataBindings.Add("Text", o, "ProdPrice");
this.txtProdRequire.DataBindings.Add("Text", o, "ProdRequire");
this.txtProdWorktime.DataBindings.Add("Text", o, "ProdWorktime");
}
删除
int index = lvUsers.SelectedItems[0].Index; lvUsers.Items.RemoveAt(index);
this.txtProdCheck.DataBindings.Clear();
this.txtProdPrice.DataBindings.Clear();
this.txtProdRequire.DataBindings.Clear();
this.txtProdWorktime.DataBindings.Clear();
class o = lbxSchName.SelectedItem as class;
if (o != null)
{
this.txtProdCheck.DataBindings.Add("Text", o, "ProdCheck");//ProdCheck为对象class的字段
this.txtProdPrice.DataBindings.Add("Text", o, "ProdPrice");
this.txtProdRequire.DataBindings.Add("Text", o, "ProdRequire");
this.txtProdWorktime.DataBindings.Add("Text", o, "ProdWorktime");
}
删除
int index = lvUsers.SelectedItems[0].Index; lvUsers.Items.RemoveAt(index);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询