I have 2 class:
public class Users { public Users() { } [Key] public int UserId { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string UserName { get; set; } public string Description { get; set; } public int GroupID { get; set; } //[ForeignKey("GroupID")] public virtual Groups Groups { get; set; } }
public class Groups { public Groups() { } [Key] public int GroupID { get; set; } [Required] public string GroupName { get; set; } public string GroupDescription { get; set; } public virtual ICollection<Users> Users { get; set; } }
I want used datagridview in winform for editing user and I want used GroupID col in datagridview with combobox and show Group record
_context = new ApplicationContext(); var query = (from o in _context.Users select o).ToList(); bi = new BindingSource(); var columnCombo = new DataGridViewComboBoxColumn(); columnCombo.DataSource = _context.Groups.ToList(); columnCombo.DisplayMember = "GroupName"; columnCombo.ValueMember = "GroupID"; columnCombo.HeaderText = "????"; columnCombo.ReadOnly = false;
bi.DataSource = _context.Users.ToList(); dataGridViewUser.DataSource = bi; dataGridViewUser.Columns[0].ReadOnly = true;
dataGridViewUser.Columns.Add(columnCombo);