Binding DataGridComboBoxColumn

后端 未结 1 955
闹比i
闹比i 2020-12-20 00:43

I am trying to bind ObservableCollection of T to DataGridComboBoxColumn of DataGrid.
DataGrid definition is :



        
1条回答
  •  心在旅途
    2020-12-20 01:13

    Since RoadTypes isn't a simple list of strings you need to tell your combobox what property it needs to display in the ComboBox. Try adding

    DisplayMemberPath="Name" 
    

    to your combobox declartion

    --

    Update:

    Okay, this is a known "feature" with WPF datagrids. The issue is that the DataGridComboBox doesn't have the DataContext of the DataGrid. I modified the binding for the ComboBox to look like this:

    
         
                 
          
          
                  
           
      
    

    I modified the code you provided in your download link and the combobox items were displayed when I opened the combobox dropdown.

    Check out some of these links for further clarification:

    http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b4b13a72-47f9-452f-85c6-6c4b5b606df5/

    How to bind collection to WPF:DataGridComboBoxColumn

    Excedrin headache #3.5.40128.1: Using combo boxes with the WPF DataGrid

    What led me to look at all of these sites is looking at the Output window and noticing the error message System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. message

    0 讨论(0)
提交回复
热议问题