DataGrid与DatagridComboboxColumn从arrayList填充 [英] Datagrid with DatagridComboboxColumn populating from an arrayList

查看:97
本文介绍了DataGrid与DatagridComboboxColumn从arrayList填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我对wpf很新,有点挣扎于它的工作方式。我想创建一个带有两个datagridcomboboxcolumn字段的DataGrid,其中的comboboxcolumns是从一个arraylist中填充的。



datagrid从一个数据表中获取itemssource,并在两个组合框列应该是两个不同的列表。默认情况下,应在这两个组合框中选择datagrid itemsource中的值。



任何人都可以告诉我一步一步的程序吗?我尝试了很多方法都失败了。



提前谢谢

Hi,

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

推荐答案

你可以实现这有助于使用MVVM和WPF架构中的绑定。



所以假设你有类(这个类将是MVVM术语中的模型),例如:

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}
}





然后让我们声明你的ViemModel



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;}
}</mytestdata></mytestdata>





和最后一个,我要定义你查看(XAML)





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

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





希望这对U有用,



Hope this this would be helpful for U,


这篇关于DataGrid与DatagridComboboxColumn从arrayList填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆