可绑定的listview似乎重复条目 [英] bindable listview seems to duplicate entries

查看:67
本文介绍了可绑定的listview似乎重复条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下载了Ian Griffiths的可绑定列表视图代码,并成功将XML文件绑定到该代码.但是,尝试添加新的信息行时遇到问题.该行会添加到数据集中,甚至会正确保存到XML文件中,但会在列表视图中两次显示该项目.以下是我用来添加新行的代码:

I downloaded Ian Griffiths bindable listview code and successfully bound an XML file to it. I am having problems when trying to add a new row of information however. The row adds to the dataset and even saves to the XML file properly but it keeps displaying the item twice in the listview. Below is the code I use to add the new row:

PC_Milestone_Form pcmf = new PC_Milestone_Form();
DialogResult res = pcmf.ShowDialog();
if (res == DialogResult.OK)
{
    //add new milestone
    ProjectCommander.MilestoneItemRow row = projectCommander.MilestoneItem.NewRow() as ProjectCommander.MilestoneItemRow;
    row["Date"] = pcmf.textBox_Date.Text;
    row["Event"] = pcmf.textBox_Milestone.Text;
    row["project_ID"] = _projectID;
    projectCommander.MilestoneItem.AddMilestoneItemRow(row);           }



问题是我是否错误地添加了行,或者我下载的可绑定listview代码是做错了什么?

除此之外,当我删除条目时,列表视图中的下一行也会消失.但是,它不会从XML文件中删除.

我上面显示的代码是否是向绑定的要素添加一行数据的正确方法?



The question is am I adding the row incorrectly or is the bindable listview code I downloaded doing something wrong?

Further to this, when I delete an entry the next row in the listview disappears as well. However it isn''t deleted from the XML file.

Is the code I show above the proper way to add a row of data to bound compenents?

推荐答案

找到解决方案.我必须用以下代码包装上面的代码:

listview.BeginUpdate();

如果条件代码在此处

projectCommander.AcceptChanges();
listview.EndUpdate();
Got the solution. I had to encase the above code with:

listview.BeginUpdate();

if condition code above here

projectCommander.AcceptChanges();
listview.EndUpdate();


这篇关于可绑定的listview似乎重复条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆