Dynamic Edit List with ComboBox in Silverlight

Dynamic Edit List with ComboBox in Silverlight

Old forum URL: forums.lhotka.net/forums/t/8281.aspx


Gareth posted on Monday, January 04, 2010

Hi, I've implemented a dynamic edit list similar to the Silverlight Demo006 example and it works fine.
I would now like to bind one of the columns to a combobox so that the selected item gives me an integer id. I've implemented it with two columns, 1 combo box and 1 textbox.
When I selected an item from the combo box nothing happens, but on pressing enter after entering data in the textbox the item attempts to save.
Is there anyway I can get it to save when an item is selected from the combo box?

RockfordLhotka replied on Monday, January 04, 2010

Watch the business object types video and look at the sample code for that video. The standard SL combobox doesn't actually do what we all want it to do in terms of binding with a selected item. The demo code includes code for a combobox control that does work correctly with data binding.

I think the SL4 combobox finally does work with data binding the way you'd expect, so that's something to look forward to in the near future :)

Gareth replied on Monday, January 04, 2010

Thanks Rocky, I've watched that video again to make sure I wasn't missing anything but I can't see why its not working. I've implemented the combobox as per the demo.

Each row of the grid has a combobox and a textbox which is slightly different to your demo implementation. I think there is some problem when binding comboboxes to individual data rows.

Gareth.

RockfordLhotka replied on Monday, January 04, 2010

In a datagrid you'll need to create your own custom column type, or use a
template column, to get the custom combobox type into the column of the
datagrid.

Gareth replied on Tuesday, January 05, 2010

Yep I have a template column like this:

(swcd:DataGridTemplateColumn Header="Supplier")
(swcd:DataGridTemplateColumn.CellTemplate)
(DataTemplate)
(tctl:ComboBox x:Name="SupplierCombo" Width="220"
ItemsSource="{Binding Source={StaticResource supplierData}, Path=Data}"
SelectedValue="{Binding Path=SupplierId, Mode=TwoWay}"
ValueMemberPath="Id" DisplayMemberPath="DisplayValue" /)
(/DataTemplate)
(/swcd:DataGridTemplateColumn.CellTemplate)
(/swcd:DataGridTemplateColumn)

Hitting the enter key on the following text column shows that the ComboBox selected value is chosen, however I really want the record to be saved on selection of a combo item. This doesn't seem to work.

Gareth.

Peran replied on Tuesday, January 05, 2010

Hi Gareth,

Your DataGridTemplateColumn xaml does not look like the examples I have seen, you may like to try the following:  You are missing a DataGridTemplateColumn.CellEditingTemplate section where your ComboBox xaml should go, for when the cell is in editing mode.  The DataGridTemplateColumn.CellTemplate section is for displaying the value when the cell is in non-editing mode, you would probably use a TextBlock here.

This link should give you an idea of the xaml required:

http://weblogs.asp.net/manishdalal/archive/2008/09/28/combobox-in-datagrid.aspx


Regards

Peran

Copyright (c) Marimer LLC