Hello ,
I am trying to add the following column through the codebehind.
ComboBoxColumn comboBoxColumn = new ComboBoxColumn();comboBoxColumn.ItemsSource = (IEnumerable) property.GetValue(applicationLookupProvider, null);comboBoxColumn.HeaderText = savedLoanTemplateField.Name;comboBoxColumn.Key = savedLoanTemplateField.Name;comboBoxColumn.DisplayMemberPath = lookupAttribute.DisplayMemberPath;comboBoxColumn.SelectedValuePath = lookupAttribute.SelectedValuePath;
loansGrid.Columns.Add(comboBoxColumn);
It properly adds the column but all the dropdown values are set to blank. It does not show the properly selectedValuePath in the dropdown. I am using reflection to add bind the ItemSource and when I set the breakpoint the IEnumerable list is getting set.
Please advise.
Pawan
Hi Pawan,
I was not able to reproduce the issue you are referring to
I have attached the sample solution I used while trying to reproduce the issue.
You could check if the values you provide to DisplayMemberPath and SelectedValuePath are correct. If they are not you should get some binding errors in the output window of VS.
If this is not the case it will be good to provide the build numbers of the assemblies you use and modify the sample solution so the issue is easily reproducible.
HTH,
Also the actual creation of the columns does not happen on form load it occurs after an event occurs once the application has been fully loaded. We are using MVVM with Prism. Any issues with using that?
I tried to move the creation of the column out of the Loaded event handler and put in Button Click event handler and I couldn't reproduce the issue.
I don't know of any issue with MVVM and Prism that might cause such an issue.
Could you please try to put together a sample app where the issue is reproducible so I could be able to help?
Regards,
It seems to be cause if you have different datatypes. One for the lookup list and the other for the list.
void MainPage_Loaded(object sender, RoutedEventArgs e) { var dataSource = new List<Data>(); var lookups = new List<Lookup>(); for (int i = 0; i < 20; i++) { dataSource.Add(new Data { Code = "5", Name = "Test" + i.ToString() }); lookups.Add(new Lookup {Id = i, Name = "Lookup" + i.ToString()}); } xwGrid.ItemsSource = dataSource; ComboBoxColumn comboBoxColumn = new ComboBoxColumn(); comboBoxColumn.ItemsSource = lookups; comboBoxColumn.HeaderText = "Data"; comboBoxColumn.Key = "Code"; comboBoxColumn.DisplayMemberPath = "Name"; comboBoxColumn.SelectedValuePath = "Id"; xwGrid.Columns.Add(comboBoxColumn); } } public class Data { public string Name { get; internal set; } public string Code { get; internal set; } } public class Lookup { public int Id { get; set; } public string Name { get; set; } }
Hello,
I am just checking the progress of this issue and was wondering if you managed to achieve your goal or if you need any further assistance on the matter.
If the above suggestion helped you solve your issue please verify the thread as answered so other users may take better advantage of it.
This is not bug for sure.
The grid use binding between cell's data and the ComboBox's SelectedValue property. In your case the The ComboBox's SelectedValue returns int(Lookups.Id) and the cell data is string(Data.Code) and that's where the problem is.
It will be best if you are able to modify the Data or the lookups so that types match. For the case where you don't have control over these types value converter should be used.
The ValueConverter won't work in our situation because since we can have 100+ of these types per row and a large result set of rows that will be returned it will be very expense as the ValueConverter must be called for each row and columns. Doesn't this seem like a bug in the control?
Yep,
the grid binds the Code property to the comb's SelectedValue property. And the problem is that you set column's SelectedValuePath to be "Id" which means that the combo box's SelectedValue prop will return the currently selected element's Id property which is of type int and the Data.Code property is of type string.
To deal with this you could change the Code/Id properties to be of equal type. Another option to use a value converter to convert <string <-> int.
I have attached the a modified version of the code you posted above so it works as expected.
One other thing - access modifier for the Code property is "internal" this means it wont be available for XamGrid which will cause the column to be read only the combo boxes will disabled.