C#ShowDialog() - 更新问题 [英] C# ShowDialog()- problem with update

查看:254
本文介绍了C#ShowDialog() - 更新问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我在做一些更改时遇到ShowDialog()问题。我将尝试用充足的代码解释整个情况。



所以我有一些计算形式,我们称之为CalcForm。在那个表单上,我有一个按钮,它将我重定向到另一个表单DetailsForm(带有一些信息的datagridview)。以下是代码:

 frmNovartisALL frm =  new  frmNovartisALL(); 
frm.ShowDialog();
.product = frm.product;
if (product == null
{
返回;
}
else
{


txt_price.Text = .product.Price1.ToString();
txt_price1.Text = this .product.Price2.ToString();
txt_price2.Text = this .product.Price3.ToString();

//

}





当我点击gridview中的链接按钮更改时,请输入此代码

  int  id =( int )gv_novartis.CurrentRow.Cells [   ID]。价值; 
product = Products.SearchByID(id);
this .Close();







所选行的所有信息都以第一种形式填写。

一切顺利。当我在CalcForm中更改一些信息并保存它们时,当我再次打开DetailsForm时,所有更改的信息也都存在。但是,问题是 - 如果我再次点击gridview中的linkbutton,在CalcForm中会在编辑之前显示信息。使其工作的唯一方法是重新启动应用程序。

我现在有点困惑,但如果你有任何想法,现在就让我吧。



也就是说 - 一切都更新了好吧在数据库中。

解决方案


听起来好像你没有在数据库更新后用数据刷新视图。



如果你想到这样的设计:



查看< - >型号< - >数据库



查看(即你的链接按钮)告诉模型更新数据库,模型更新数据库并回复查看更新后的值。



通过这种方式,您可以确定视图中显示的内容是数据库中存储的内容。



Jegan

Hello,

I`m having problem with ShowDialog() when I make some changes. I`ll try to explain whole situation provided with adequate code.

So I`m having form for some calculation, lets call it CalcForm. On that form I have button which redirect me to another form DetailsForm(datagridview with some information). Here is the code:

 frmNovartisALL frm = new frmNovartisALL();
            frm.ShowDialog();
            this.product = frm.product;
            if (product == null)
            {
                return;
            }
            else
            {
             

                txt_price.Text = this.product.Price1.ToString();
                txt_price1.Text = this.product.Price2.ToString();
                txt_price2.Text = this.product.Price3.ToString();
        
//
        
            }



When I click on linkbutton "Change" in gridview, whit this code

int id = (int)gv_novartis.CurrentRow.Cells["ID"].Value;
           product = Products.SearchByID(id);
           this.Close();




all information about selected row are populated in first form.
And everything works well. When I change some information in CalcForm and save them, and when I again open DetailsForm all changed information are there also. But, here is the problem- if I click again on linkbutton in gridview- in CalcForm are shown information before editing. Only way to make it work is to restart application.
I now its bit confusing, but if you have any ideas- plese let me now.

Just to say also- everything is updated well in database.

解决方案

Hi Sounds like you not refreshing the view with data after the database updated.

If you think of the design like this:

View <--> Model <--> Database

View (i.e. your link button) tell the model to update the database, the model updates the database and replies to view with the updated value.

This way you can be sure what is shown in the view is what is stored in the database.

Jegan


这篇关于C#ShowDialog() - 更新问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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