Tag: bindingsource

如何正确地将bindingSource更改提交到源数据库?

我设置了DataGridView和其他UI组件,以允许用户编辑来自SQLite DB的数据。 但是这些更改(即使它们在应用程序中正确显示)也不会保存到DB。 我试过这段代码 aBindingSource.EndEdit(); dbDataSetA.GetChanges(); aTableAdapter.Update(dbDataSetA.Accounts); 但是有并发exception: System.Data.DBConcurrencyException未处理Message = Concurrency violation:UpdateCommand影响了预期的1条记录中的0条。 那么我应该如何将绑定源更改提交给DB,伙计们呢? POST EDIT我启动程序时遇到此exception,然后单击DataGridView中的第二行,然后单击第三行,此时程序引发并发exception。 希望他的帮助能让这个问题更加详细。 先谢谢你,伙计们!

来自BindingSource的C#刷新文本框

我正在刷新使用BindingSource对象的Windows窗体控件时遇到困难。 我们有一个CAB / MVP / SCSF客户端,我(实际上是“我们”,因为它是团队的努力)正在开发,它将与在远程服务器上运行的WCF服务进行交互。 (这是我们的第一次尝试,因此我们处于学习模式)。 其中一个调用(从Presenter)到服务返回一个包含3个DataTable的DataSet,名为“Contract”,“Loan”和“Terms”。 每个表只包含一行。 当服务返回数据集时,我们将它存储在类成员变量的SmartPart / View中,方法是调用名为BindData()的视图中的函数,并将数据集传递给演示者类的视图; private System.Data.DataSet _ds = null; public void BindData(System.Data.DataSet ds) { string sErr = “”; try { _ds = ds; // save to private member variable // more code goes down here } } 我们试图将三个DataTable中的每一个绑定到各种各样的Windows Forms TextBox,MaskedEditBoxes和Infragistics UltraComboEditor Dropdowncombobox我们创建了三个BindingSource对象,每个对象使用VS2008 IDE对应一个DataTable。 private System.Windows.Forms.BindingSource bindsrcContract; private […]

如何对绑定到自定义对象集合的DataGridView进行排序?

所以我一直在关注Windows Forms控件的数据绑定这个指南 (MAD道具给作者,这个指南很棒),我用它来创建一个自定义类并将DataGridView绑定到这个类的集合: class CompleteJobListEntry { private string _jobName; private Image _jobStatus; private DateTime _jobAddedDate; private string _jobAddedScanner; private string _jobAddedUser; private string _jobLastActivity; private DateTime _jobActivityDate; private string _jobActivityUser; public string JobName { get { return _jobName; } set { this._jobName = value; } } public Image JobStatus { get { return _jobStatus; } […]

无法使用bindingsource刷新datagridview

目标: 单击“添加”或“删除”按钮后,应使用文档中的最新数据刷新datagridview。 问题: 通过删除或添加新数据进行更改后,无法刷新datagridview。 我正在使用与datagridview的数据源链接的绑定源。 我用不同的解决方案尝试了一切,并从不同的论坛阅读建议,但我仍然无法解决这个问题。 我也尝试使用这些语法“BindingSource.ResetBindings(false)”,“BindingSource.Refresh()”等但没有结果。 以下链接: 如何刷新绑定源 http://www.eggheadcafe.com/community/aspnet/2/10114324/datagridview-refresh-from-another-form.aspx http://blogs.msdn.com/b/dchandnani/archive/2005/03/15/396387.aspx http://bytes.com/topic/c-sharp/answers/812061-problem-refresh-datagridview bSrcStock.DataSource = myProductrepository.GetAllProductList(); dgridStock.DataSource = null; dgridStock.DataSource = bSrcStock; bSrcStock.ResetBindings(true); dgridStock.Columns[0].Width = 101; dgridStock.Columns[1].Width = 65; dgridStock.Columns[2].Width = 80; dgridStock.Columns[3].Width = 120; dgridStock.Columns[4].Width = 90;

为什么我需要在SaveChanges之前更改绑定源位置

我有一个小型的WinForms演示应用程序。 其中一个表格是我的添加新人表格。 我使用了Details View而不是Data Sources中的DataGridView 。 当我输入数据并单击导航器上的保存按钮时,没有任何更改,但是我在表单Load AddNew之后放置了MovePrevious和MoveNext ,一切都按预期工作。 public partial class AddPersonForm : Form { private readonly DemoContext _context; public AddPersonForm() { _context = new DemoContext(); InitializeComponent(); } protected override void OnLoad(EventArgs e) { _context.People.Load(); personBindingSource.DataSource = _context.People.Local.ToBindingList(); personBindingSource.AddNew(); personBindingSource.MovePrevious(); personBindingSource.MoveNext(); base.OnLoad(e); } private void personBindingNavigatorSaveItem_Click(object sender, EventArgs e) { int changes = _context.SaveChanges(); […]

C#中DataSet和DataGridView之间的DataBinding

我目前在表单上有一个DataGridView,我想在DataSet中使用DataTable,从SQlite数据库填充(使用System.Data.SQlite)。 所以,我在数据库和DataSet之间有一个DataAdapter,可以直接将DataGridView数据源设置为DataTable。 这显示很好。 我的问题是:为什么我要在这里使用绑定源? 很多教程都说你可以使用或不使用它。 但除了增加额外的步骤之外,它有什么用处吗? 另外,如果我想在更改DataGridView时更新数据库,怎么办呢? DataSet是否自动更新 – 所以我只需要告诉DataAdapter更新? 或者绑定源是否有用? 谢谢!

DataGridView / DataTable | rowState不会更改

我遇到了将数据绑定到DataGridView的问题。 我有一个inheritance自DataGridView的类MyDataGridView。 我的数据网格视图数据源是一个BindingSource对象,它将DataTable作为数据源。 问题是,当我通过(我的)DataGridView对象进行更改时,rowState保持’未修改’而不是修改; 即使DataTable中的值发生了变化(这也是我的更新不起作用的原因,因为它认为rowState是未定义的)。 请注意,直接对DataTable进行更改可以正常工作。 谢谢 (:

绑定到仅显示列表中第一个项目的嵌套属性

我试图将.NET 4.5中的C#Winforms中的ListBox控件绑定到具有嵌套属性的对象列表,我希望将其用于DisplayMember。 除了当我将DisplayMember设置为嵌套属性时,列表框仅显示一个项目,即使列表中有两个项目被绑定,它也是有效的。 如果我注释掉用于设置DisplayMember的代码,则listBox显示两个项目。 这是框架中的错误吗? 我想避免添加另一个属性或覆盖ToString(),如果我可以,因为我正在实现MVP并且希望将我的视图逻辑保持在我的视图中。 以下是一些示例代码。 public partial class Form1 : Form { public Form1() { InitializeComponent(); var bindingSource = new BindingSource(); var listOfMyItems = new BindingList { new MyItem { Number = 1, NestedItem = new NestedItem { Name = “name1”, Note = “note1” } }, new MyItem { Number = 2, NestedItem […]

自定义StronglyTyped BindingSource项目添加

我想自定义添加一个新项目到BindingSource (所有强类型),如下面的MSDN文章所述: 如何:使用Windows窗体绑定源自定义项目添加 下面的代码导致InvalidOperationException :添加到BindingSource列表的对象必须都是相同的类型。 此外,对象myTypesBindingSource.Current似乎是一个DataRowView ,里面有我的相关行。 如何自定义强类型BindingSource ? private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.someDataSet = new myDB.SomeDataSet(); this.myTypesBindingSource = new System.Windows.Forms.BindingSource(this.components); this.myTypesTableAdapter = new myDB.SomeDataSetTableAdapters.myTypesTableAdapter(); this.tableAdapterManager = new myDB.SomeDataSetTableAdapters.TableAdapterManager(); this.myTypesBindingNavigator = new System.Windows.Forms.BindingNavigator(this.components); this.someIntValueTextBox = new System.Windows.Forms.TextBox(); // someDataSet this.someDataSet.DataSetName = “SomeDataSet”; this.someDataSet.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema; // myTypesBindingSource // As generated: // […]

.NET BindingSourcefilter语法参考

您可以使用BindingSource的Filter属性来执行类似过滤的SQL。 例如: bindingSource.Filter= “Activated = 1” 是否有类似文档的确切语法? 我想检查字段是否不是DBNull,所以我尝试了“Field!= NULL”但它给出了语法错误。