相关疑难解决方法(0)

List <T> vs BindingList <T>优点/ DisAdvantages

有人可以描述两者之间的区别对于我的项目.

目前我有一个List<MyClass>并将BindingSource设置为它,并将DataGridView设置为BindingSource.

我已经实现了IEditableObject,当调用CancelEdit时,我将我的对象恢复到它的状态Memberwise.Clone()

将我的List更改为BindingList会解决这个问题,使用BindingList有什么好处?

.net c# data-binding datagridview winforms

85
推荐指数
2
解决办法
7万
查看次数

如何使用Entity Framework以DataGridView可编辑和上下文跟踪更改的方式过滤数据?

我正在使用C#Windows Form Application使用以下代码使用Entity Framework(EFWinForms)从sql server数据库表填充数据:

MyEntityDataModel db = new MyEntityDataModel();
MyEDS = new EntityDataSource();
MyEDS.DbContext = db;
MyDataGridView.DataSource = MyEDS;
MyDataGridView.DataMember = "MyTable";
Run Code Online (Sandbox Code Playgroud)

它工作正常.用户编辑时,添加数据; 可以使用以下代码保存数据:

MyEDS.SaveChanges();
Run Code Online (Sandbox Code Playgroud)

我想要一种通过实体数据源过滤这些数据的方法,以便MyDataGridView保持可编辑状态,用户在过滤数据中完成的任何更新仍然可以保存回数据库.注意:当使用linq to entity过滤数据时,它工作得很好,但它只是填充了用户无法再次编辑或更新的数据快照.

.net c# entity-framework datagridview winforms

7
推荐指数
1
解决办法
1万
查看次数

当 DataSource 是 BindingList 时过滤 BindingSource

我从excel表中读取并为BindingList写了这个,在Form_Load中,它被设置为一个数据源作为BindingSource:

bd = new BindingSource(); //instance of BindingSource
bd.DataSource = ExcelOPS.LerExcel(); //LerExcel() method return a BindingList<T>

gvFiltro.DataSource = bd; //set a DataGridView named gvFiltro DataSource property
bindNav.BindingSource = bd; //set a BindingNavigator source
Run Code Online (Sandbox Code Playgroud)

这工作很好!我打算为此 DataGridView gvFiltro 创建一个组合框作为过滤器,因此在组合框的 SelectedIndexChanged 事件中,我尝试这样做:

this.gvFiltro.DataSource = null;
bd.Filter = string.Format("TAG_FAZENDA like '%{0}%'", cbTagFaz.Text);
gvFiltro.DataSource = bd;
gvFiltro.Update();
gvFiltro.Refresh();

bindNav.BindingSource = bd;
bindNav.Update();
bindNav.Refresh();
Run Code Online (Sandbox Code Playgroud)

但是 DataGridView 不会改变。我错过了什么?

.net c# datagridview bindingsource winforms

3
推荐指数
1
解决办法
8344
查看次数