I have a Collection of Values in an Array of Strings, or in a List or whatever, and what i want is to set this Collection of values as the Collection of items into all the ComboBoxes in a column as DataGridComboBo x in WPF.
I think i don't have other way to access this Collection of Values and bind it equally to all the ComboBoxes (in XAML) beside the DataContext. But can i access the DataContext of a DataGrid from a DatGridComboBox Column (in XAML)? Can i do it? How?
How i set (in XAML) in DatagridComboBo x to put this Collection of Items equally in all ComboBoxes? How i can achieve this?
Here is my XAML:
And here is my Code Behind:
I think i don't have other way to access this Collection of Values and bind it equally to all the ComboBoxes (in XAML) beside the DataContext. But can i access the DataContext of a DataGrid from a DatGridComboBox Column (in XAML)? Can i do it? How?
How i set (in XAML) in DatagridComboBo x to put this Collection of Items equally in all ComboBoxes? How i can achieve this?
Here is my XAML:
Code:
<Grid Name="grid1"> <DataGrid Name="dataGrid" AutoGenerateColumns="True"> <DataGrid.Columns> <DataGridComboBoxColumn Header="Options" Width="100" ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=DataGrid}, Path=DataContext}"/> </DataGrid.Columns> </DataGrid> </Grid>
And here is my Code Behind:
Code:
public MainWindow() { InitializeComponent(); string[] abc = {"10", "20", "30", "40", "50"}; dataGrid.DataContext = abc; }
Comment