Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

How to bind to DataGrid ComboBox Column List of List of string, one List by cell ( WPF )

$
0
0

Hello 

I'm learning WPF

I searched and searched on the Internet but didn't find the solution. 

I have a List o people. Each person has one or more phone numbers. 

I managed to bind all text attributes to the DataGrid, but comboboxes appear empty.

I want ComboBoxes to display, when clicked, all the phone numbers of the selected person (row).

------------------------------------------------------------------------------------------------

My data struct is:

public class Person

{

    public int ID {get;set;}

    public string Name {get;set;}

    // all other text attributes

    public TelInfo Tels {get;set;}

}

// App.MainList is a List<Person>

public class TelInfo

{

    public int ID {get;set;}

    public List<TelData> PhoneNbrs {get;set;}

}

public class TelData

{

    public int ID {get;set;}

    public string Number{get;set;}

}

----------------------------------------------------------------------------------

My XAML (what reffers to the DataGridComboBoxColumn) is:

                    <DataGridTemplateColumn Header="Teléfonos" Width="160">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <ComboBox Height="30" SelectedIndex="0" 
                                          ItemsSource="{ Binding Path=App.MainList }" DisplayMemberPath="Tels.PhoneNbrs.Number" 
                                          SelectedItem="{ Binding Tels }" SelectedValue="{ ID }"
                                          SelectedValuePath="Tels.ID" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
--------------------------------------------------------------------------------------------------------

What is wrong? I suspect it's something in the XAML ...

Thanks in advance for your help

Pablo


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>