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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统