I have a OneToMeny relation object model for User and UserGroup like this:
public class UserGroup : BaseModel, IEquatable<UserGroup>
{
private long _userGroupId;
private string _userGroupName;
public long UserGroupId
{
get { return _userGroupId; }
set
{
_userGroupId = value;
NotifyOfPropertyChange(() => UserGroupId);
}
}
public string UserGroupName
{
get { return _userGroupName; }
set
{
_userGroupName = value;
NotifyOfPropertyChange(() => UserGroupName);
}
}
public UserGroup GetCopy(bool getNew)
{
var copy = new UserGroup
{
UserGroupId = UserGroupId,
UserGroupName = UserGroupName,
State = getNew ? ModelStates.New : State,
};
return copy;
}
public bool Equals(UserGroup other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return _userGroupId == other._userGroupId;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((UserGroup) obj);
}
public override int GetHashCode()
{
return _userGroupId.GetHashCode();
}
}
public class User : BaseModel
{
private long _userId;
private string _userName;
private string _password;
private string _firstName;
private string _lastName;
private List<UserGroup> _userGroups;
public User()
{
_userGroups = new List<UserGroup>();
}
public long UserId
{
get { return _userId; }
set
{
_userId = value;
NotifyOfPropertyChange(() => UserId);
}
}
public string UserName
{
get { return _userName; }
set
{
_userName = value;
NotifyOfPropertyChange(() => UserName);
}
}
public string Password
{
get { return _password; }
set
{
_password = value;
NotifyOfPropertyChange(() => Password);
}
}
public string FirstName
{
get { return _firstName; }
set
{
_firstName = value;
NotifyOfPropertyChange(() => FirstName);
}
}
public string LastName
{
get { return _lastName; }
set
{
_lastName = value;
NotifyOfPropertyChange(() => LastName);
}
}
public List<UserGroup> UserGroups
{
get { return _userGroups; }
set
{
_userGroups = value;
NotifyOfPropertyChange(() => UserGroups);
}
}
}
I will use a Devexpress GridControl to save and load user model. So I have a GridControl like this:
<dxg:GridControl ItemsSource="{Binding Users}" >
<dxg:GridControl.Columns>
<dxg:GridColumn x:Name="FirstName"
Width="10"
FieldName="FirstName" />
<dxg:GridColumn x:Name="LastName"
Width="10"
FieldName="LastName" />
<dxg:GridColumn x:Name="UserName"
Width="10"
FieldName="UserName" />
<dxg:GridColumn x:Name="Password"
Width="10"
FieldName="Password">
<dxg:GridColumn.EditSettings>
<dxe:PasswordBoxEditSettings />
</dxg:GridColumn.EditSettings>
</dxg:GridColumn>
<dxg:GridColumn x:Name="UserGroups"
Width="15"
FieldName="UserGroups">
<dxg:GridColumn.EditSettings>
<dxe:ComboBoxEditSettings ItemsSource="{Binding UserGroups}"
DisplayMember="UserGroupName" >
<dxe:ComboBoxEditSettings.StyleSettings>
<dxe:CheckedComboBoxStyleSettings />
</dxe:ComboBoxEditSettings.StyleSettings>
</dxe:ComboBoxEditSettings>
</dxg:GridColumn.EditSettings>
</dxg:GridColumn>
</dxg:GridControl.Columns>
<dxg:GridControl.View>
<dxg:TableView x:Name="TableViewAllEmployees"
AutoWidth="True"
NewItemRowPosition="Top"
ShowGroupPanel="False" />
</dxg:GridControl.View>
</dxg:GridControl>
Unfortunately in runtime combobox open in readonly mode and I cann't select any record form it. Please tell me how to enable combobox.
In extra I use Devexpress, Caliburn in WPF project.