Click here to Skip to main content
15,303,572 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I use a LINQ join query between user and groups as the DataSource of a DataViewGrid to display data.
The problem is that I would like to use a DataGridViewComboBoxColumn so the user is able to change the Group. But the combo does not work as I imagined.

This is my code:

C#
var query = from u in context.User
join ur in context.UserRole on u.ID equals r.UserID
join r in context.Role on ur.RoleID.ToString() equals r.ID.ToString() 
select new
{u.ID,
u.Nick,
u.LastLogin, 
Role = ur == null ? String.Empty : r.Name
};
DataGridViewTextBoxColumn ColID = new DataGridViewTextBoxColumn();
DataGridViewTextBoxColumn ColNick = new DataGridViewTextBoxColumn();
DataGridViewTextBoxColumn ColLast = new DataGridViewTextBoxColumn();
DataGridViewComboBoxColumn ColRole = new DataGridViewComboBoxColumn();

ColID.DataPropertyName = "ID";
ColNick.DataPropertyName = "Nick";
ColLast.DataPropertyName = "LastLogin";
ColRole.DataPropertyName = "Role";
ColRole.DataSource = context.Role.ToList();
ColRole.ValueMember = "ID";

userDataGridView.Columns.Add(ColID);
userDataGridView.Columns.Add(ColNick);
userDataGridView.Columns.Add(ColLast);
userDataGridView.Columns.Add(ColRole);

userDataGridView.DataSource = query.ToList();


I set the JoinQuery between user and group entities to the DataGridView DataSource and set the group dbset as the DataGridViewComboBoxColumn DataSource.
But I'm getting an error that says datagridviewcomboboxcolumn cell value not valid and even when it displays the proper group of the user the dropdown effect of the combo does not work so I cannot change it.

I read that the "cell value not valid" error could be caused if by the data if I have a user that is assigned to a missing group but I have checked the data and it matches perfectly.

Any idea about what I'm missing. Thanks

What I have tried:

I check the database twice and the user and group data matchs perfectly.
I tried debbuging but the DataError event of the dataviewgrid has no code.
Posted

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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