How to bind the same collection of values into all ComboBoxes in a DataGridComboBox?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Miguel RBR
    New Member
    • Mar 2011
    • 1

    How to bind the same collection of values into all ComboBoxes in a DataGridComboBox?

    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:
    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;
    }
  • Mary Anne
    New Member
    • Jun 2011
    • 5

    #2
    I want is to set Collection of values as the Collection of items into all the ComboBoxes in a column as DataGridComboBo xColumn in WPF.
    (...)xmlns:loca l="clr-namespace:WpfAp p"(...)

    Code:
    <Grid Name="grid1">
        <DataGrid Name="dataGrid" AutoGenerateColumns="True">
            <DataGrid.Columns>
                <DataGridComboBoxColumn Header="Options" Width="100"/>
            </DataGrid.Columns>
        </DataGrid>
    </Grid>
    And here is my Code Behind:
    Code:
    public class TestClass
    {
        private static string[] stringArray = { "Option One", "Option Two", "Option Three" };
    
        public static string[] StringArray
        {
            get
            {
                return stringArray;
            }
        }
    }
    Last edited by Niheel; Jul 19 '11, 06:58 AM. Reason: code tags

    Comment

    Working...