DATAGRIDCOMBOBOXCOLUM won't change itemssource
I've used Combos inside datagrids a lot and never had any problems but for some reason on this one page it doesn't. When I try to change the entry I get a cellendedit event but the cell stays selected and shows a thin red line around the outside. I can't open any other combobox in the display either. I populate it with an enum converted to an observable list and bind the column to a datatable.
Code:
Public Enum ItemTypes As Integer
ignore
Products
Ingredients
Consumables
Taxation
Equipment
Utilities
Maintenance
Rentals
Monthly
Other
Last
End Enum
Code:
Public Function GetSubTypesCollection() As ObservableCollection(Of ItemsClass)
Dim col As New ObservableCollection(Of ItemsClass)
For i = 4 To ItemTypes.Last - 1
Dim entry As New ItemsClass([Enum].GetName(GetType(ItemTypes), i), i)
col.Add(entry)
Next
Return col
End Function
Code:
Dim cbCol = New DataGridComboBoxColumn
cbCol.Header = "Type"
cbCol.ItemsSource = GetSubTypesCollection()
cbCol.DisplayMemberPath = "Name"
cbCol.SelectedValuePath = "ID"
cbCol.SelectedValueBinding = New Binding("typeid")
cbCol.Width = New DataGridLength(1, DataGridLengthUnitType.Star)
dg.Columns.Add(cbCol)
The only thing I can think of would be that the selectedvalue is something the datatable doesn't like. I msgbox() the entire collection and made sure it was just integers though (typeid is an integer column too).
Oh the datagrid declaration!
Code:
<DataGrid Name="dg" Grid.Row="0" Grid.Column="0" IsReadOnly="False" CanUserAddRows="False" CanUserDeleteRows="False" AutoGenerateColumns="False"/>
I am about to erase and redo it all but I'm hoping someone can spot my error
Re: DATAGRIDCOMBOBOXCOLUM won't change itemssource
Ack I figured it out. I messed up creating the list of classes so the ID is a string, not a number. I was looking at the wrong observablecollection before. It doesn't like a string to set an integer field. Go figure!
Re: DATAGRIDCOMBOBOXCOLUM won't change itemssource
Actually no, that wasn't it. I set up a test combobox to see what the selectedvalue would be but messed up and said SelectedValue instead of SelectedValuePath. Once I noticed and fixed that the list is working fine. I double checked the comboboxcolumn and it is fine too. Still a mystery... I will probably see if tomorrow morning first thing and think "How dumb am I to not see that?"
Re: DATAGRIDCOMBOBOXCOLUM won't change itemssource
I finally found out how to get the value of a datagrid cell. Cast e.EditingElement to the type of column then just use it like any other control
Code:
Private Sub dg_CellEditEnding(sender As Object, e As DataGridCellEditEndingEventArgs) Handles dg.CellEditEnding
Dim mycb As ComboBox = CType(e.EditingElement, ComboBox)
MsgBox(mycb.Text + " " + mycb.SelectedValue.ToString)
'btnCommit.IsEnabled = True
'btnReject.IsEnabled = True
End Sub
I checked and the combobox does indeed have a valid selectedvalue. The mystery deepens