1

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.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Gogetter
  • 11
  • 1
  • See [this question and its answer](https://stackoverflow.com/questions/11428707/access-a-control-from-within-a-datatemplate-with-its-identifying-name). – Kilazur Feb 15 '19 at 15:38
  • Hi Kilazur, which answer, none are accepted, the one with +3 votes? – Gogetter Feb 15 '19 at 16:11
  • for example, yes, but the others are also valid. Basically, you can access this control by its name, or rethink your solution. – Kilazur Feb 18 '19 at 10:37

0 Answers0