c# - Adding duplicated values to a BindingList -
when add information bindinglist, gets duplicated... dont how...
i have class lists:
public videorepository() { videos = new bindinglist<video>(); videosfiltered = new bindinglist<video>(); } public bindinglist<video> videos { get; set; } public bindinglist<video> videosfiltered { get; set; } public void addvideo(video video) { console.writeline("size 1 " + videos.count); videos.add(video); videosfiltered.add(video); console.writeline("size 2 " + videos.count); } when call method addvideo first print shows size 1 0 , second print shows size 2 2. when using debuger...
what problem? drunk?
i've noticed both videos , videosfiltered have public setters. way can behavior described if external code (not shown here) sets them 1 , same bindinglist<video> instance.
you'd better remove public setters.
or, modify code follows
public void addvideo(video video) { console.writeline("size 1 " + videos.count); videos.add(video); if (videosfiltered != videos) videosfiltered.add(video); console.writeline("size 2 " + videos.count); }
Comments
Post a Comment