This is a migrated thread and some comments may be shown as answers.

ComboBoxColumn not editable

2 Answers 84 Views
DataGrid
This is a migrated thread and some comments may be shown as answers.
Josiah
Top achievements
Rank 1
Josiah asked on 03 Feb 2017, 05:24 PM

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

2 Answers, 1 is accepted

Sort by
0
Ves
Telerik team
answered on 08 Feb 2017, 12:15 PM
Hi Josiah,

I can confirm, that we were able to replicate an issue in a scenario like yours. While we investigate the possible fixes and a new build is released, please use the following workaround - wrap the ComboBox's ItemsSouce strings in objects and set SelectedValuePath property of the DataGrdiComboBoxColumn with the name of the property, holding the actual string.

E.g. populate DepartmentNumbers in the viewmodel like this:

auditLocations.DepartmentNumbers = auditAccountDepartments.Select(d => new MyData() { deptN = d.DepartmentNumber}).ToList();

This way, the value for SelectedValuePath would be "deptN"

I have attached an example to demonstrate this.


Best regards,
Ves
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Josiah
Top achievements
Rank 1
answered on 09 Feb 2017, 08:35 PM
Thanks, Ves. I've got it working now. Much appreciated.
Tags
DataGrid
Asked by
Josiah
Top achievements
Rank 1
Answers by
Ves
Telerik team
Josiah
Top achievements
Rank 1
Share this question
or