Search code examples
wpfdatagriddatagridcomboboxcolumn

Display 2 values in a WPF DataGridComboBoxColumn DisplayMemberPath


I have a series of objects representing some data points listed in a DataGridComboBoxColumn. Setting the DisplayMemeberPath property I can display a single value, say the x coordinate. What I would like to do though is display both the x and y coordinates in 'x, y' format. Any ideas on how to do this?


Solution

  • you should not use DisplayMemberPath, but instead use a DataTemplate, and a TemplateColumn

        <ComboBox>
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding First}" Margin="0,0,10,0" />
                        <TextBlock Text="{Binding Second}"/>
                    </StackPanel>
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>