Hi,
I have a RadDataGrid with a ComboBoxColumn populated from a list of integers. Both the ItemsSource of my grid and the ItemsSourcePath of my ComboBoxColumn are dynamically populated from a database. I have set the SelectedValuePath and PropertyName of the column so that the default value is also dynamically chosen. The default values are populating as expected, however, when I try to edit a row, which would open the dropdown, I get an exception and an attached debugger is called.
Here is my grid:
<
tel:RadDataGrid
x:Name
=
"SpecialLocationsGrid"
Margin
=
"100,40,100,40"
VerticalAlignment
=
"Top"
HorizontalAlignment
=
"Center"
AutoGenerateColumns
=
"False"
UserColumnReorderMode
=
"None"
UserEditMode
=
"Inline"
UserFilterMode
=
"Disabled"
UserGroupMode
=
"Disabled"
UserSortMode
=
"Single"
ItemsSource
=
"{Binding SpecialLocations}"
>
<
tel:RadDataGrid.Columns
>
<
tel:DataGridComboBoxColumn
ItemsSourcePath
=
"DepartmentNumbers"
SelectedValuePath
=
"DepartmentNumber"
PropertyName
=
"DepartmentNumber"
Header
=
"Department #"
/>
</
tel:RadDataGrid.Columns
>
</
tel:RadDataGrid
>
And here is my code:
// In the DataContext of the page
private
ObservableCollection<AuditLocationViewModel> _specialLocations;
public
ObservableCollection<AuditLocationViewModel> SpecialLocations
{
get
{
return
_specialLocations;
}
set
{
SetProperty(
ref
_specialLocations, value);
}
}
// This method is called in the constructor of the page the grid sits in
public
async Task LoadSpecialLocationsData()
{
_specialLocations =
new
ObservableCollection<AuditLocationViewModel>();
var auditAccountDepartments = await AuditAccountDepartmentDataSource.AuditAccountDepartmentSyncTable.Select(n =>
new
{ n.AuditAccountDepartmentId, n.DepartmentNumber }).OrderBy(o => o.DepartmentNumber).ToListAsync();
// grab from db
var auditLocationDetails = await AuditLocationDataSource.AuditLocationSyncTable.Select(n =>
new
{ n.AuditAccountDepartmentId }).ToListAsync();
// grab from db
for
(
int
i = 0; i < auditLocationDetails.Count; i++)
{
AuditLocationViewModel auditLocations =
new
AuditLocationViewModel();
Guid auditAccountDepartmentId = auditLocationDetails[i].AuditAccountDepartmentId;
auditLocations.DepartmentNumber = auditAccountDepartments.Where(a => a.AuditAccountDepartmentId == auditAccountDepartmentId).Select(d => d.DepartmentNumber).First();
// set DepartmentNumber for this row
auditLocations.DepartmentNumbers = auditAccountDepartments.Select(d => d.DepartmentNumber).ToList();
// DepartmentNumbers is just the list of all the values of DepartmentNumber in the db
_specialLocations.Add(auditLocations);
}
SpecialLocations = _specialLocations;
}
// And finally, my object of the collection
public
class
AuditLocationViewModel : ViewModelBase
{
public
int
DepartmentNumber {
get
;
set
; }
public
List<
int
> DepartmentNumbers {
get
;
set
; }
}
My question is, basically, why am I getting an exception when I try to open the dropdown and edit? In addition, am I using the SelectedValuePath and PropertyName properties of the ComboBoxColumn correctly?
Thank you,
Josiah