ComboBox in CellEditingTemplate

橙三吉。 提交于 2019-12-11 08:36:14

问题


I am trying to use a ComboBox in a DataGrid CellEditingTemplate, binding to an existing DataTable. When I double click the item, the ComboBox displays, but there is no data in it. I've researched different options for a couple of days, but nothing seems to work.

<DataGridTemplateColumn Header=" Venue" CanUserSort="False">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Venue}"/>
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
    <DataGridTemplateColumn.CellEditingTemplate>
        <DataTemplate>
            <ComboBox  ItemsSource="{Binding Path=dtVenues, ElementName=MyWindow}"
                       DisplayMemberPath="Venue" 
                       SelectedValuePath="Venue"
                       Text="{Binding Venue}"/> 
        </DataTemplate>
    </DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>

The DataTable dtVenues is declared as Public in code behind (VB). Can anyone please point me in the right direction for a solution.


回答1:


I'm guessing that you've declared the dtVenues collection for your ComboBoxes in the code behind of your Window and set the Window.DataContext property value to the code behind class in one way or another. If that is true, then I believe that you need to change your Binding slightly to address the Window.DataContext:

<ComboBox ItemsSource="{Binding Path=DataContext.dtVenues, ElementName=MyWindow}"... />


来源:https://stackoverflow.com/questions/20355088/combobox-in-celleditingtemplate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!