Click here to Skip to main content
13,596,105 members
Rate this:
Please Sign up or sign in to vote.
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
Posted 25-Dec-12 20:59pm
Updated 25-Dec-12 23:36pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web04-2016 | 2.8.180621.3 | Last Updated 26 Dec 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100