Click here to Skip to main content
14,977,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I am pretty new to wpf and kinda struggling with the way it works. I would like to create a DataGrid with two datagridcomboboxcolumn fields with the comboboxcolumns being populated from an arraylist.

The datagrid takes itemssource from a datatable and the list of values in the two combobox columns should be two different lists. By default, the value in the datagrid itemsource should be selected in these two comboboxes.

Can any one tell me the step by step procedure to do this? I have tried many ways and all failed.

Thanks in advance
Updated 25-Dec-12 23:36pm

1 solution

Hi, you can achive this with help of usage MVVM and ocre of a bindings in WPF architecture.

So lets pretend that you have class (this class would be your Model in MVVM terminology), for example:
public class MyTestData
  public int ID {get;set;}
  public string[] Array1 {get;set}
  public string[] Array2 {get;set}

then lets declare your ViemModel
public class MainVM:Galasoft.MvvmLight.ViewModelBase
  public MainVM():base{
ListOfData =new ObservableCollection<mytestdata>();
//there you can add some fake data

  public ObservableCollection<mytestdata> ListOfData {get;set;}

and the last one, i'm going to define you View (XAML)

<datagrid datacontext="{Binding local:MainVM}" itemssource="{Binding ListOfData}">
<datagridtemplatecolumn height="100" header="Array1">
       <combobox itemssource="{Binding Array1}" />
<datagridtemplatecolumn height="100" header="Array2">
       <combobox itemssource="{Binding Array2}" />

Hope this this would be helpful for U,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900