Datagrid视图本身并不令人耳目一新 [英] Datagrid view is not refreshing by itself

查看:57
本文介绍了Datagrid视图本身并不令人耳目一新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,当我点击数据网格视图的行或单元格时,它们会填充到文本框中进行编辑,在我编辑和查看更新后,如果我关闭并运行数据网格,则数据网格视图不会立即更改再次形成,它正在改变。我的要求是我应该在点击更新按钮后立即更改。我用于更新点击的代码是:

Actually, when I click on the rows or cells of the datagrid view, they are populating into the text boxes to edit, after I editing and clecked on the update, the datagridview is not changing instantly, if I close and run the form again, it is changing. My requirement is it should change immediately after I click on the update button. The code I am using for update click is:

private void btnUpdate_Click(object sender, EventArgs e)
       {

           SqlConnection con = Helper.getconnection();
           SqlCommand cmd = new SqlCommand();
           cmd.Connection = con;
           cmd.CommandType = CommandType.Text;
           string PrjID = txtPrjID.Text;
           string PrjName = txtPrjNmae.Text;
           string Description = txtPrjdescription.Text;
           string Date = txtPrjDate.Text;
           string Size = txtPrjSize.Text;
           string Manager = txtPrjManager.Text;
           cmd.CommandText = "Update Projects set ProjectName= '" + PrjName + "', Description='" + Description + "', DateStarted='" + Date + "',TeamSize='" + Size + "',Manager='" + Manager + "' where ProjectID= " + PrjID + " ";
           MessageBox.Show("Project Details are updated");
           dataGridView2.Update();
           dataGridView2.Refresh();
           con.Open();
           cmd.ExecuteNonQuery();
           con.Close();

           }

推荐答案

试试这个



http://www.aspdotnet-suresh .com / 2011/02 / how-to-inserteditupdate-and-delete-data.html [ ^ ]



在Onrowupdating Event中添加您的代码gridview。
Try this

http://www.aspdotnet-suresh.com/2011/02/how-to-inserteditupdate-and-delete-data.html[^]

Add your code inside Onrowupdating Event of gridview.


执行命令后进行网格更新和刷新





表示首先执行你的命令

ie

cmd.ExecuteNonQuery();





然后



然后刷新你的datagridview
make ur grid update and refresh after you execute your command


means first execute your command
i.e
cmd.ExecuteNonQuery();


then

then refresh your datagridview


我通过使用BindData();
I have solved the problem by using BindData();


这篇关于Datagrid视图本身并不令人耳目一新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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