I've set the dataschema manually in my ultraGrid1 (version: 12.1.20121.2135).
I have a List<Person> and every Person class has a List<Order>.
The datasource property of the grid is simply set at runtime, like:
List<Person> People = DummyRepository.GetPeople();
ultraGrid1.Datasource = People;
At first none of the people have an Order in their collection. At runtime the user can add an order. When the user does this I set the datasource again with People. But unfortunatly it doesn't show the added Order. I tried after setting the datasource property:
ultraGrid1.Rows.Refresh(Infragistics.Win.UltraWinGrid.RefreshRow.ReloadData)
ultraGrid1.Rows.Refresh(Infragistics.Win.UltraWinGrid.RefreshRow.RefreshDisplay)
And even:
ultraGrid1.Databind()
Nothing helps.
The only thing that seems to help is setting the datasource to null first and then setting the datasource to the collection. But then I have another problem, which I'm not sure I should get in to right now. You see I also have custom Row Layouts which I havent mentioned yet. But if I set the datasource to null the grid loses the custom row layout I designed in the designer at runtime.
I can set the datasource to null and keep displaylayouts by first saving and then loading the displaylayout, but... That shouldn't be the solution. Feels pretty forced to me. Besides I'll lose other properties like spacing between rows and such appearances.
So... How can I solve this?
Hello Georgi,
Thank you for making an improved sample for me and a little video. I appreciate it very much.
It works in my real project aswell. So, nice find. But this solution gives me other problems (because ofcourse in my real project the objects are more complex plus I like to code with obj.equals(obj) which needs to be the actual instance of the object as you know).
In other words, if I'm going to implement this solution I'll have to rewrite a lot.
So my question is: Why does it work like this?
If you create entirely new objects the grid seems to be tricked into reloading the data. But if I use your Refresh method with ReloadData it doesn't. Why?
oh p.s: I did alter the LINQ query a bit, like so:
var activePeople = (from p in DummyRespository.People where p.IsActive select new Person { Name = p.Name, IsActive = p.IsActive, Orders = p.Orders.ToList() }).ToList();
Because I like to work with strongly typed instances. I also applied this in my real project.
p.p.s.: Also found out that first setting datasource equal to an empty list and then to a filled list has the desired effect???
this is the sample :
Hello DannyvDK,
Thanks for attached sample. Maybe the easiest way to solve your issue, could be if you modify your Linq. For example:
private void RefreshGridActive()
{
var activePeople = (from p in DummyRespository.People
where p.IsActive
select new
Name = p.Name,
IsActive = p.IsActive,
Order = p.Orders.ToList()
}).ToList();
this.ultraGrid1.DataSource = activePeople;
this.ultraGrid1.Rows.Refresh(Infragistics.Win.UltraWinGrid.RefreshRow.ReloadData);
this.ultraGrid1.Rows.ExpandAll(true);
}
Please take a look on attached video file and sample for more details and if you have any questions, feel free to write us
Regards
Hey Mike,
I know about BindingLists and have my reasons not to use them. So let me deal with the headaches. :-)
In my real project, the collection is already an empty list (I believe I already got this tip some time ago from Infragistics but new requirements made the problem return).
So I have attached a small project to illustrate my problem. It's called PersonOrderRefreshing.
1) Run it.
2) Press "add order" and you'll see the grid refresh correctly.
3) Now in method RefreshGrid() of Form1 put the call to RefreshGridAll in comment and decomment RefreshGridActive.
4) Run the project.
5) Press "add order" and you won't see the grid refresh properly. Why?
6) Decomment all code in RefreshGrid
7) Run it.
8) Add orders and try to switch between active/all People. Doesn't work either. Why?
Thank you in advance for looking into my problem.
Hi,
List<T> is not a good data source to use for bound controls. This interface will only provide basic support for binding, and it doesn't have all the property notificaitons for data binding. I recommend changing to BindngList<T>, instead. I'm not sure if that will solve this particular problem, but it will certainly save you some headaches down the road.
If it doesn't solve the issue, the my guess is that grid cannot build the proper structure from your data source. Implementing your own data objects like this can be tricky and the grid will build the bands up front as soon as it's bound. So if the data source originally has no Order data, then the BindingManager might be unable to create the child band structure and that's why it's not working.
Make sure that, even when there are no Order rows, you Person object always returns an empty list (not null).
If that still doesn't help, see if you can post a small sample project here so I can check it out and I will figure out why it's not working in your case and let you know how to fix it.