I'm attempting to build a form which contains an editable datagrid using IronPython and XAML.
I extract my data from the database and append it to a list. I then set this list as the itemsource for a combo box. This works and the combo box dropdown populates with the required options.
However If I now move my combo box into the DataGridTemplateColumn, it no longer populates the dropdown despite being named the same.
XAML:
<DataGrid AutoGenerateColumns="False" CanUserResizeRows="False" CanUserSortColumns="False" ClipboardCopyMode="IncludeHeader" Height="189" HorizontalAlignment="Left" Margin="6,16,0,0" SelectionUnit="Cell" VerticalAlignment="Top" Width="700" Name="Dtgrd_ELExceptions" CanUserAddRows="True" ItemsSource="{Binding}">
<DataGrid.Columns>
<DataGridTextColumn Header="Usertype" Binding="{Binding Usertype}" />
<DataGridTemplateColumn Header="Header">
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding itemc}" Name="combo" />
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate />
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Charge Rate" Binding="{Binding Rate}"/>
</DataGrid.Columns>
</DataGrid>
IronPython
#Get list of categories
def Categorylist():
strSql5 = "Select Name from Usr_VarChargeCategories"
_tikitDbAccess.Open(strSql5)
if _tikitDbAccess._dr is not None:
dr = _tikitDbAccess._dr
if dr.HasRows:
itemc = list()
while dr.Read():
itemc.append(dr.GetString(0))
combo.ItemsSource = itemc
dr.Close()
_tikitDbAccess.Close()
What am I missing? Having researched a bit I think that the combobox in the Datagridtemplatecolumn is not exposed in the same way as when it is placed outside the datagrid. But i cant seem to find a way to reference it or an alternative method.