Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
At the beginning, when I assign my collection to a control's DataSource, it follows what is in the collection. During the execution of my program, when the collection changes, I don't see any change in the control's content. How can I make the control follow the latest changes of the collection?

What I have tried:

The only way I know is to set DataSource to null and then set it to the collection again! But I think, this may not be a good idea.
Posted
Updated 26-Apr-18 2:26am
Comments
Maciej Los 26-Apr-18 7:56am    
You mean custom control (user control) or standard windows form control?
ilostmyid2 26-Apr-18 8:29am    
it's indeed a RadListView control

1 solution

Try using a BindingList:
C#
class MyClass
    {
    public string Str { get; set; }
    public int I { get; set; }
    }
BindingList<MyClass> myBindingList = new BindingList<MyClass>();
private void button1_Click(object sender, EventArgs e)
    {
    myBindingList.Add(new MyClass() { Str = "s1", I = 100 });
    myBindingList.Add(new MyClass() { Str = "s2", I = 101 });
    myBindingList.Add(new MyClass() { Str = "s3", I = 102 });
    myBindingList.Add(new MyClass() { Str = "s4", I = 103 });
    myBindingList.Add(new MyClass() { Str = "s5", I = 104 });
    MyDataGridView.DataSource = myBindingList;
    }
private void button2_Click(object sender, EventArgs e)
    {
    myBindingList.Add(new MyClass() { Str = "sX", I = 666 });
    }
Every time you click Button2, a string will be added to teh DataGridView.
 
Share this answer
 
Comments
ilostmyid2 26-Apr-18 8:30am    
thank you. is there any way other than using BindingList? indeed the data source comes from a web service hosting on linux. can't make it return a BindingList.
OriginalGriff 26-Apr-18 8:36am    
What does it return? A web service will normally return either XML or JSON and you can process those into anything you like!

You can use a BindingSource as an intermediary (though I've not needed to) or any collection with implements IBindingList directly.
ilostmyid2 26-Apr-18 10:01am    
we're programming in C# winforms, web services are accessed via NuSoap in Linux. the return value of web service is a simple structure.
OriginalGriff 26-Apr-18 10:06am    
So your Web service returns a SOAP message - if that's a single item structure what's the problem with using a BindingList as the DataSource? You are presumably using a collection of some form at present, or are you adding them directly to an internal collection of your control?
ilostmyid2 26-Apr-18 10:18am    
no, it's an array which is returned and i don't change it nor fill another collection or array based on it. i just use it as it's returned. I'll try BindingList for this purpose. thanx. I know few about it, but I hope I'll succeed.

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