Load data from DB to combodatagridview in windows C# RRS feed

  • Question

  • I have a DataGridViewComboBox column. I'm trying to populate the ComboBox dropdown list at runtime from database ..can u pls give the code..


    Wednesday, October 10, 2012 5:52 AM


  • Hi shanmu995

    You don't give a lot of context, but you can try this.

    1. Use the ItemsSource property and set a binding in the XAML.


    2. Attach to the Loaded event, and set the ItemsSource property there.

    Sample XAML: (this will require that you set the DataContext to something that provides these public properties.)

        ItemsSource="{Binding Employees}" 
        SelectedValueBinding="{Binding SelectedEmployee}"               

    Sample Loaded event xaml and code:

    <DataGridComboBoxColumn FrameworkElement.Loaded="DataGridComboBoxColumn_Loaded" />

    and the code

    private void DataGridComboBoxColumn_Loaded(object sender, RoutedEventArgs e) {
        ((DataGridComboBoxColumn)sender).ItemsSource = 
            new Employee[] 
                new Employee("Martin"), 
                new Employee("Peter") 

    Is that what you are looking for?

    • Proposed as answer by Martin Lottering Thursday, October 11, 2012 6:27 PM
    • Marked as answer by shanmu995 Tuesday, October 16, 2012 2:12 PM
    Thursday, October 11, 2012 6:16 PM