在Silverlight中动态添加Datagrid中的行 [英] Dynamically add row in Datagrid in Silverlight
本文介绍了在Silverlight中动态添加Datagrid中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我想在Datagrid中动态添加行,在Silverlight中有TextBox,ComboBox等控件,
when用户点击新按钮。
谢谢和问候
Anurag
Hi All
I want to add dynamically row in Datagrid , having controls like TextBox, ComboBox etc. in silverlight,
when user click on new button.
Thanks and Regards
Anurag
推荐答案
您可以拥有一个包含控件值的类,并维护该类的全局集合...
ObservableCollection< employee> obj = new ObservableCollection< employee>()
其中Employee是你定义的类。
现在点击按钮,你可以添加新的像这样的行
You can have a class which holds the value of the controls whatever you want and maintain a global collection of that class...
ObservableCollection<employee> obj = new ObservableCollection<employee>()
where Employee is your defined class.
Now on button click , you can add the new row like this
Private void AddRows(sender,args){
obj.Add(new Employee() {.... });
datagrid1.itemsource=obj;
}
这篇关于在Silverlight中动态添加Datagrid中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文