DataGrid如何点击外面一个按钮,给他加一条可编辑行
比如 我点击添加按钮,那么DataGrid下面就添加一行,然后里面可以输入值,在点击保存就保存到数据库,这个怎么做? datagrid 数据库
[解决办法]
貌似这个问题,我前些日子在论坛里给别人回答过...
那就用ObservableCollection 就可以了
using System.Collections.ObjectModel;
public partial class SilverlightControl1 : UserControl
{
ObservableCollection<User> collect = new ObservableCollection<User>();
public SilverlightControl1()
{
InitializeComponent();
User user1 = new User() { UserName = "张三", Hobby = "玩Dota" };
User user2 = new User() { UserName = "李四", Hobby = "看人玩Dota" };
collect.Add(user1);
collect.Add(user2);
mydg.ItemsSource = collect;
}
private void button1_Click(object sender, RoutedEventArgs e)
{
collect.Add(new User() { UserName = "", Hobby = "" });
}
}
public class User
{
public string UserName { get; set; }
public string Hobby { get; set; }
}