Hello,
Does anyone know if there is a way to allow the cell being edited in the Grid to be able to display a combo for the user to select an option OR allow the user to type text into the editing cell that isn't in the combo's list? It seems as if the combo is read only or only allows selection of what's in the list.
Thanks
Hi,
XamGrid does not supports ComboBox columns out of the box at the moment, this feature will be included in our next volume release. However you could implement this as CustomColumn - to learn how to do so take a look at Devin Rader's blog post. This approach uses the ComboBox control from MS sdk which does not support editing.
Another approach is described in this forum thread where XamComboEditor is put inside an EditorTemplate of a Template column. Using this approach you should set CustomValueEnteredAction="Add" if you want the typed text to be added to the XamComboEditor's ItemSource.
HTH
Konstantin,
I implemented Devin Raders ComboBox column back in January, now the project I'm working on needs to have a grid that has an integer as the cell's value (the employee's ID) - and display the employee's name, and have the combo box allow the user to select an employee from the list.
Is this something that's possible? In the ResolveDisplayElement, could something do a lookup of items bound to the combo's Itemsource and retrieve the employee name if it knows the employee ID? (Kind of like a basic lookup in a combo box where if you have a SelectedValuePath = xxx and then the DisplayMemberPath = yyy)
Thanks.
Hi rhavlic,
I suppose you could easyily add a SelectedValuePath property to your ComboBoxColumn and to and set it to the ComboBox similar to DisplayMemberPath. Then you will need to supply ItemSource of objects that have the ID and corresponding name as properties.
Another approach I can thing of is providing a Value converter which converts the IDs into Names and vice versa.
Hope this helps.
Thanks Konstantin, I've actually tried both approaches without any luck. I can get it to work after an item is edited, but initially when the column loads, the ItemSource is set to Null - so when the ResolveDisplayElement method is called, I can't bind to the ItemSource bound to the drop down to do the value converter or get the item from the list.
I've stepped through, and tried to see if it's the order in which I'm binding to the grid, and it seems correct.
On the Page's OnNavigatedTo event, I'm binding the ComboBoxColumn to the list of cars:
// Executes when the user navigates to this page. protected override void OnNavigatedTo(NavigationEventArgs e) { List<Car> cars = new List<Car>(); cars.Add(new Car() { Name = "Lightening", CarID = 1}); cars.Add(new Car() { Name = "Doc", CarID = 2}); cars.Add(new Car() { Name = "Mator", CarID = 3 }); cars.Add(new Car() { Name = "Sally", CarID = 4 }); cars.Add(new Car() { Name = "Fillmore", CarID = 5 }); cars.Add(new Car() { Name = "Sarge", CarID = 6 }); cars.Add(new Car() { Name = "Ramon", CarID = 7 });
List<DemoData> data = new List<DemoData>(); data.Add(new DemoData() { PropA = "A", PropB = 10, PropC = 1 }); data.Add(new DemoData() { PropA = "B", PropB = 20, PropC = 2 }); data.Add(new DemoData() { PropA = "C", PropB = 30, PropC = 3 }); data.Add(new DemoData() { PropA = "D", PropB = 40, PropC = 4 }); data.Add(new DemoData() { PropA = "E", PropB = 60, PropC = 1 }); data.Add(new DemoData() { PropA = "F", PropB = 70, PropC = 2 }); data.Add(new DemoData() { PropA = "G", PropB = 80, PropC = 3 });
((ComboBoxColumn)this.xamwebgrid1.Columns["PropC"]).ItemsSource = cars; this.xamwebgrid1.ItemsSource = data; }
Then in the ComboBoxColumnContentProvider's ResolveDisplayElement method:
public override FrameworkElement ResolveDisplayElement(Cell cell, System.Windows.Data.Binding cellBinding) { //When it gets here, the _combobox.ItemSource is always Null even though it's already been bound to the //itemsource from the Page.OnNavigatedTo ComboBoxColumn column = (ComboBoxColumn)cell.Column;
Binding textBinding = new Binding();
if (column.DisplayMemberPath!=null) textBinding.Path = new PropertyPath(string.Format("{0}.{1}", column.Key, column.DisplayMemberPath)); else textBinding.Path = new PropertyPath(column.Key);
textBinding.Mode = BindingMode.TwoWay; this._tb.SetBinding(TextBlock.TextProperty, textBinding);
return _tb; }
In the ResolveEditorControl method however, the ItemSource is populated. Do you have any idea why it's not getting populated when the ResolveDisplayElement method is called?
Thanks so much
Hi rhavlick,
I have attached sample solution that might be of help.
It basically add SelectedValuePath property to the ComboBoxColumn which is set to the ComboBox editor in ResolveEditorControl.
In ResolveDisplayElement I used the ComboBox as a proxy and if there is DIsplayMemberPath set to the column textBox's Text property is bound to comboBox.SelectedValue and the path of the binding is DispalyMemberPath.
Regards
Hi Konstantin ,
In the meantime I found a solution, but I also will try the new 11.1 release.
Regards ,
Hi mileca,
sorry for the late response,
It seams that the my sample code does not work well when the virtualization of the grid is used. If you haven't resolve the issue so far I could suggest you to try the new 11.1 voluem release. We are now shipping a ComboBox column out of the box for xamGrid. If this is not a solution for you I could spent some time to make a wokrind sample.
Regards,
Hi Konstantin,I have use your sample and work ok with small amount of data. When I bind grid to large data source from databases in combo is not corect value. Maybe I'm doing something wrong. Did You notice this? When I add 30 more item to DemoData in your code, in combo is not corect value.
Thanks so much Konstantin, this is exactly what I've been trying to do. I don't know why mine wasn't working, I must have done something wrong.
Many thanks for working on it over the weekend too - I really really apprecaite it.