Hello,
I have a radgridview with a datasource linked to entity framework and it works fine.
I have an entity called "USER" and I display all my users in the radgridview, it works just fine.
In my USER entity, I have an attribute "GROUP" which is a collection :
public virtual ICollection<GROUP> GROUP { get; set; }
I would like to add a second radgridview to display groups details when you select a user. I think I have to play with event SelectionChanged on the main radgridview but I don't really know how to handle this.
Thanks,
Florian
4 Answers, 1 is accepted
Thank you for writing.
It looks like you are having a scenario which is suitable for creating a hierarchical RadGridView. We have an example demonstrating how you can use Database First approach and show the data in the grid. Additionally, you can check the following KB article using Code First approach, it has data models similar to the ones you describe. The actual binding of the templates is at the end of the article.
In case using a hierarchical grid is not suitable and you would like to display the child data associated with each record in a separate RadGridView you can handle the CurrentRowChanged event. Additional information about the selected and current row is available here: https://docs.telerik.com/devtools/winforms/gridview/rows/selected-rows-and-current-row
I hope this helps. Should you have further questions please do not hesitate to write back.
Regards,
Hristo
Progress Telerik
Thanks for your response.
Your second solution is the best for my case but I still have some difficulties.
I load my main gridview to display all users :
radGridViewUserManagement.DataSource = _entities.T_USER.Local.ToBindingList();
It works fine, I can insert/update/delete rows and save to my database with _entities.SaveChanges();
When I handle the CurrentRowChanged event :
private void radGridViewUserManagement_CurrentRowChanged(object sender, CurrentRowChangedEventArgs e)
{
if (e.CurrentRow != null && e.CurrentRow is GridViewDataRowInfo)
{
currentUser = (T_USER) radGridViewUserManagement.CurrentRow.DataBoundItem;
radGridViewSelectedGroups.DataSource = currentUser.T_GROUP.ToList();
}
}
I can display my current user Groups, but the view is never updated if I add some groups programmatically with currentUser.T_GROUP.Add(testGroup);
I think my problem is the using of ToList() function when I set the DataSource.
I tried many things but I cannot update the radGridViewSelectedGroups.
Thanks for your help Hristo
Thank you for writing back.
It appears that the grid is not receiving a notification that you have changed its data source collection. If that is really the case it will not update automatically. You can try using a BindingList just as shown in the documentation article:
dbContext.Customers.Load();
this
.radGridView1.DataSource =
this
.dbContext.Customers.Local.ToBindingList();
I hope this helps. Let me know if you have other questions.
Regards,
Hristo
Progress Telerik