GridControl

基本设置

https://blog.csdn.net/fangyu723/article/details/129987808

傻瓜式操作

var lis = new List<T_StationAddress>();
gcStationAddress.DataSource = bindinglis;
//对bindinglis做各种操作
//做完之后再执行:gcStationAddress.DataSource = bindinglis;

数据绑定模式

普通的DataSoure绑定

public Form1
{
   BindingList<T_StationAddress> StationAddress = new BindingList<T_StationAddress>();
   gcStationAddress.DataSource = StationAddress;
   //可简单写为
   gcStationAddress.DataSource = new BindingList<T_StationAddress>();
}
private void Operation_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
{
    switch (e.Button.Caption)
    {
        case "删除": gridView2.DeleteSelectedRows(); break;
        case "新增": gridView2.AddNewRow(); break;
        case "保存": var i=gridView2.DataSource; break;
    }
}

注意点,DataSource必须绑定BindingList,表格才可以编辑

BindingList和List的转换关系

//List转Binding,需要将List传入构造函数中
gcStationAddress.DataSource =new BindingList<T_StationAddress>(new List<T_StationAddress>());
//Binding转List,有现成的扩展方法
List<T_StationAddress> lis = new BindingList<T_StationAddress>().ToList();

MVVM模式

MVVM

posted @ 2023-08-28 02:49  回首起了风沙  Views(8)  Comments(0Edit  收藏  举报