C#我有datagridview(还没有存储在数据库中)。我可以从这个datagridview更新信息 [英] C# I have datagridview(not stored in database yet).how can I update info from that datagridview

查看:82
本文介绍了C#我有datagridview(还没有存储在数据库中)。我可以从这个datagridview更新信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好。我有datagridview我添加信息,我想更新这个信息,打开包含文本框,标签和点击按钮提交的新表格。然后选择数据网格中的信息改变。我怎么能这样做。我可以问题是信息没有存储在数据库中。我无法从datagridview更改数据。有什么建议吗?谢谢。



我尝试过:



什么都不显示



Hello.I have datagridview which I add info,I want to update this info,opening new form which contains textbox,label and click button submit.Then the info in datagridview which selected shoud change.How can I do this.My problem is that information is not stored in database.I cannot change data from datagridview.Any suggestions?Thank you.

What I have tried:

nothing is to show

private void update_Click(object sender, EventArgs e)
       {

           ProductClass up = new ProductClass
           {

               PriceBuy=Convert.ToDecimal(dg1.SelectedRows[0].Cells["colPriceBuy"].Value)
           };
           //this form open to edit
           Form9 edit = new Form9(up);
           edit.ShowDialog();
           update_CellVAlueChanged(null, null);



       }

       private void update_CellVAlueChanged(object sender, DataGridViewCellEventArgs e)
       {
         //maybe proqmaticaly I can change value of cells when I submit button of Form9
       }
   }

推荐答案

第一个要做的是向Form9类添加属性或构造函数以访问当前数据:在两种表格之间传递信息,第1部分:父母对儿童 [ ^ ]

然后使用属性将新数据恢复为原始格式:在两种表格之间转移信息,第2部分:儿童到家长 [ ^ ](如果您使用Form9中的属性将现有数据放入表单中,则可以使用相同的属性将其恢复。)



那么你需要找出来DGV中的哪一行包含您需要的信息:

The first thing to do is to add a property or a constructor to the Form9 class to access the current data: Transferring information between two forms, Part 1: Parent to Child[^]
And then use a property to return the new data back to the original form: Transferring information between two forms, Part 2: Child to Parent[^] (If you used a property in Form9 to get the existing data into the form, you can use teh same property to get it back).

Then you need to find out which row in the DGV contains the info you need:
foreach (DataGridViewRow row in myDataGridView.SelectedRows)
    {
    Form9 edit = new Form9();
    edit.Value = row.Cells[0].Value.ToString();
    if (edit.ShowDialog() == DialogResult.OK)
        {
        row.Cells[0].Value = edit.Value;
        }
    }





BTW:帮个忙,并停止使用Visual Studio默认值一切的名字 - 你可能还记得今天的TextBox8是手机号码,但是当你必须在三周内修改它时,你会这样吗?使用描述性名称 - 例如tbMobileNo - 您的代码变得更容易阅读,更自我记录,更易于维护 - 并且编码速度更快,因为Intellisense可以通过三次击键来tbMobile,其中TextBox8需要思考大概和8次击键...

打电话给你的表格是明智的,而不是Form1,Form2,......



BTW: Do yourself a favour, and stop using Visual Studio default names for everything - you may remember that "TextBox8" is the mobile number today, but when you have to modify it in three weeks time, will you then? Use descriptive names - "tbMobileNo" for example - and your code becomes easier to read, more self documenting, easier to maintain - and surprisingly quicker to code because Intellisense can get to to "tbMobile" in three keystrokes, where "TextBox8" takes thinking about and 8 keystrokes...
Call your forms something sensible, not "Form1", "Form2", ...


这篇关于C#我有datagridview(还没有存储在数据库中)。我可以从这个datagridview更新信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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