图片框绑定触发绑定DataRow上的更改 [英] Picture Box Binding Triggers Changes on Bound DataRow

查看:65
本文介绍了图片框绑定触发绑定DataRow上的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个关于"图片"的严重问题。 VS.NET 2008/2010中的绑定

I have a severe problem concerning "Picture" binding in VS.NET 2008/2010

我制作了一个简单的示例应用程序,用于绑定"类别"。 Windows窗体中的表格,使用"拖放"功能。来自DataSource的技术(DataSource在我的例子中是一个DataSet,表类别,Northwind DataBase)。

I made a simple sample application binding the "Categories" table in a Windows Form, using the "drag/drop" technology from DataSource (DataSource is in my case a DataSet, table Categories, Northwind DataBase).

所以,VS为我创建了下一个代码:

So, VS created next code for me:

(1)Bindings:

  CategoryId:(DataBindings).Text = categoriesBindingSource - CategoryID

 CategoryId : (DataBindings).Text = categoriesBindingSource - CategoryID

CategoryName:(DataBindings).Text = categoriesBindingSource - CategoryName

CategoryName : (DataBindings).Text = categoriesBindingSource - CategoryName

描述:(DataBindings).Text = categoriesBindingSource - Description

Description: (DataBindings).Text = categoriesBindingSource - Description

图片:(DataBindings).Image = categoriesBindingSource - Picture

Picture : (DataBindings).Image = categoriesBindingSource - Picture

(2)Form"Load"事件:

private void Form1_Load(对象发件人,EventArgs e)

{

             this.categoriesTableAdapter.Fill(this.categoryTds.Categories);

private void Form1_Load(object sender, EventArgs e)
{
            this.categoriesTableAdapter.Fill(this.categoryTds.Categories);

}

(3 )"保存"事件:

private void categoriesBindingNavigatorSaveItem_Click(object sender,EventArgs e)

{

             this.Validate();

            this.categoriesBindingSource.EndEdit();

            MessageBox.Show(this.categoryTds.HasChanges()。ToString());

            this.tableAdapterManager.UpdateAll(this.categoryTds);

private void categoriesBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
            this.Validate();
            this.categoriesBindingSource.EndEdit();
            MessageBox.Show(this.categoryTds.HasChanges().ToString());
            this.tableAdapterManager.UpdateAll(this.categoryTds);

}

这是非常基本的东西,我唯一添加的是" MessageBox",跟踪shanges。

So pretty basic stuff, the only thing i've added is the "MessageBox", to track shanges.

那么,现在的问题是什么?当我浏览表单记录(详细信息模式)时,

So, what's the problem now ? when I navigate trhough the form records (Details mode),

我没有做任何更改,点击"保存"按钮。 BindingNavigator上的按钮和我的MessageBox

i make no changes, hit the "Save" button on the BindingNavigator, and my MessageBox

告诉我,类别表有"更改",虽然我没有更改单个项目,

shows me that the Category table has "changes", although i didn't change a single item,

我只是导航!

然后我删除了"Picture Binding"。 (设置为(无)),重新启动程序,导航,

Then i removed the "Picture Binding" (set to (none)), restarted the program, navigated,

按下"保存"按钮按钮,然后我的消息框提到"无变化"。

pushed the "save" button, and then my messagebox mentioned "no-changes".

因此,结论是导航bindingsource触发更改/更改事件

So, the conclusion is that navigating the bindingsource triggers the changing/changed events

"PictureBox"的>,因此行设置为"已修改",即使我没有更改任何内容。

of the "PictureBox", so rows are set as "Modified", even though I didn't change a thing.

如何解决此问题? 我只想看到我的行设置为"已修改"。当用户在文本框中放入一些不同的文本或选择另一个图片时!似乎非常明显,不是吗???

How to solve this please ?  I only want to see my rows set to "modified" when the user put some different text in the textboxes or selected another Picture ! Seems very obvious, isn't it ???

我有 发现了很多关于这个话题,提出了一些"管道"。将PictureBox绑定在"Never-Update"中的解决方案模式,这是有效的,但是当用户选择另一张图片时,该行不会以这种方式更新,我必须编写自己的代码来"粘贴"。
图像字段中的新图片字节数组,BindingSource上的pull和EndEdit(),这是一种解决方法,但这应该由.NET框架本身处理!

I have  found a lot about this topic, proposing some "plumbing" solution like binding the PictureBox in "Never-Update" mode, this works, but when the user chooses another picture, the row isn't updated this way and I have to write my own code to "paste" the new picture-byte-array within the Image field, pull and EndEdit() on the BindingSource, this is a workaround, but this should be handled by the .NET framework itself !

另一种可能的"管道"。我发现的解决方案是跟踪ColumnChanging(),ColumnChanged(),RowChanging()和RowChanged()事件,因为这些事件是"触发"的。导航时(由于PictureBox),然后将当前行
的原始值与当前值进行比较,如果没有更改,则在CurrentRow上执行AcceptChanges()。再一次,一个管道解决方案应该在.NET框架本身处理好了!

Another possible "plumbing" solution i found was tracking the ColumnChanging(),ColumnChanged(),RowChanging() and RowChanged() events, cause these are "triggered" while navigating (due to the PictureBox), then compare the original values of the current row with the current values, and in case no changes, execute an AcceptChanges() on the CurrentRow. Again, a plumbing solution that should be handled ones for good in the .NET framework itself !

来吧MS家伙,这应该不是那么难解决,不是吗?或者我们是否应该再次手动离开BindingSources和代码绑定?我们在.NET 2.0中开始我们的.NET开发,MS推出了BindingSources,而且
仍然是一个伟大的发明,但是  ;请,还要解决上面提到的这些小事情,并在框架内做好,很多人会很高兴,而且会浪费更少的时间...... 

Come on MS guys, this shouldn't be so hard to solve, isn't it ? Or should we all leave BindingSources and code the bindings all by hand again ? We started our .NET development in .NET 2.0, MS introduced the BindingSources which were and are still a great invention, but please, also solve these little things like mentioned above ones and for good in the framework itself, many people will be pleased, and lesss time will be lost ... 

  Greetz,

 Greetz,

Emmanuel Nuyttens。

Emmanuel Nuyttens.

推荐答案

Hello Greetz,

Hello Greetz,

没有足够的信息可以帮助您解决问题。 您能否将测试项目上传到skydrive?它始终是获得解决方案的最快方式,并且通常由您自己尝试在
清洁新项目中复制问题。

There is no where near enough information to help you with your question. Would you please upload a  test project to skydrive? It's always the fastest way to get to the solution, and often by your self while trying to replicate the problem in a clean new project.


这篇关于图片框绑定触发绑定DataRow上的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆