Click here to Skip to main content
15,880,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
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);           }

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?
Updated 2-Feb-11 19:14pm
Sergey Alexandrovich Kryukov 30-Jan-11 18:54pm    
Please, where is the reference to download the code you're using?
Paul Hildebrandt 30-Jan-11 20:00pm

for bindable listview code
Henry Minute 30-Jan-11 20:18pm    
What version of Visual Studio are you using? Which version of C# too, please?
Paul Hildebrandt 31-Jan-11 14:05pm    
Visual Studio Tools for Applications 2.0 (VS 2008)
C# 2008
.NET 3.5 SP1
Mike_Finch 8-Jun-11 17:40pm    
I have the deletion problem also. I have a BindingList for a data source, which I provide to the BindableListView. When I remove an item from the BindingList, the ListViewItem in the BindableListView associated with that item disappears, and so does the one for the next item.

When I call BindingList.Remove() to remove the desired item, I observe that:

* BindableListView.currencyManager_ItemChanged() is called, where the given ItemChangedEventArgs.Index is -1.

* That causes BindableListView.LoadItemsFromSource() to be called, which repopulates the ListViewItems.

* Then, BindableListView.bindingList_ListChanged() is called, where the given ListChangedEventArgs.ListChangedType is ItemDeleted. This causes another ListViewItem to be erroneously removed.

I experience this problem even when I encase my item removal in BeginUpdate...EndUpdate calls as Paul Hildebrandt suggested in his solution.

(For my own reference, this is a comment to a question titled "bindable listview seems to duplicate entries".)

1 solution

Got the solution. I had to encase the above code with:


if condition code above here

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900