Click here to Skip to main content
15,041,788 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
   DataGridComboBoxColumn dataCombox = new DataGridComboBoxColumn();
          dataCombox.Header ="Name";

           Binding b = new Binding();
           b.Path = new PropertyPath("ComboxClass");
          dataCombox.ItemsSource = listCom;
          dataCombox.SelectedItemBinding = b;

          dataCombox.SelectedValuePath = "PriceTypeId";
          dataCombox.DisplayMemberPath = "PriceTypeValue";

and then Binding
ObservableCollection<CommClassForDataGrid> listData = new ObservableCollection<CommClassForDataGrid>();
            string path = comSelect.comPath;
            IEnumerable<string> fileNameList = new List<string>();
            fileNameList = FileTools.GetLastDirXmlNodeString(path);
            foreach (string filePath in fileNameList)
                CommClassForDataGrid com = new CommClassForDataGrid();
                CommClassForComBox cb = new CommClassForComBox();
                cb.PriceTypeValue = "xiaoming";
                cb.PriceTypeId = comSelect.flag;
            this.dgForData.ItemsSource = listData;

I hope to get a set of default is xiaoming DataGridComboBoxColumn data.
Now the way the interface displays no value

1 solution

Bind a List to the ItemsSource of the DataGridComboBoxColumn and then specify the SelectedItemBinding, DisplayMemberPath, SelectedValueBinding or the SelectedValuePath property.

Below is sample code from social.msdn site:


    <DataGrid AutoGenerateColumns="False" Height="200" HorizontalAlignment="Left" Name="dataGrid1" VerticalAlignment="Top" Width="308">
        <DataGridTextColumn Header="Name" Binding="{Binding Name}"/>
        <DataGridComboBoxColumn x:Name="ComboBoxColumn" Header="Position"  SelectedItemBinding="{Binding Position}"/>


public partial class MainWindow : Window
    public ObservableCollection<Player> Players { get; set; }
    public ObservableCollection<string> Positions { get; set; }
    public MainWindow()
      Positions = new ObservableCollection<string>() { "Forward", "Defense", "Goalie" };
      Players = new ObservableCollection<Player>(){
                    new Player() {Name = "Tom",Position= "Forward"},
                    new Player() {Name = "Dick", Position= "Defense"},
                    new Player() {Name = "Harry", Position= "Goalie"}
      ComboBoxColumn.ItemsSource = Positions;
      dataGrid1.ItemsSource = Players;

  public class Player
    public string Name { set; get; }
    public string Position { set; get; }
Member 10501182 14-Jul-15 16:49pm
Please can you explain how do I get the value selected in the Combo Box.
Every row will have an independent ComboBox.
User can select a row and further select a particular value from the Combo Box
After Selecting the Value in the Combo Box the User clicks on Submit.
I want the Selected Value of the Combo Box of the Selected Row.
Please can you explain how this can be done?


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900