Datagridview在Windows窗体中编辑应用程序 [英] Datagridview Editing in windows form Application

查看:136
本文介绍了Datagridview在Windows窗体中编辑应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨专家。



如何将数据从一个网格视图移动到另一个网格视图。我想将所选行从一个网格视图移动到另一个网格视图当我点击Move按钮时。



现在我只是将数据绑定到网格视图中。并删除所选的行。

Hi experts.

How to move the data from one grid view to another grid view.I want move the Selected Row from one grid view to another grid view when i click the Move button.

Now i just bind the data into grid view. And delete the selected Row.

try
                {
                    if (dataGridView2.Rows.Count != 0 && dataGridView2.SelectedRows[0].Index != dataGridView2.Rows.Count)
                    {
                        cn.Open();
                        cmd = new SqlCommand("DELETE FROM Phone_Number WHERE phone=" + dataGridView2.SelectedRows[0].Cells[1].Value.ToString() + "", cn);
                        cmd.ExecuteNonQuery();
                        dataGridView2.Rows.RemoveAt(dataGridView2.SelectedRows[0].Index);

                        MessageBox.Show("Deleted..!!");
                        cn.Close();
                    }



但我不知道如何将所选行移动到另一个网格视图。

我试试这段代码。但它没有用。它返回错误消息。




But i don't know how to move the selected rows to another grid view.
i try this code. But it is not working. It return the error Message.

private void button5_Click(object sender, EventArgs e)
       {
           dataGridView3.Rows.Add(dataGridView2.SelectedRows[0].Cells[1].Value.ToString());

           //dataGridView3.DataSource = dataGridView2.SelectedRows;

       }



错误消息是:没有行可以添加到没有列的DataGridView控件。列必须先添加。



我该怎么办?请指导我。


The error message is: "No row can be added to a DataGridView control that does not have columns. Columns must be added first."

What i have to do?? Please Guide me.

推荐答案

检查过去的答案

将行从一个DataGridView复制到C#中的其他DataGridView [ ^ ]
Check this past answer
Copy Rows from One DataGridView to Other DataGridView in C#[^]


First make确保使用DATASET为DataGridView控件更新DataSource属性...



然后在Button Click事件上..将所选行传输到DataSet,在那里你要移动记录...和....然后再次更新两个DataGridView控件的DataSource属性...



在第二次更新DataSource之前...不要忘了从第一个DataGridView的OLD表/数据集中删除相同的行...





只需简单的步骤......


1。将数据集中的表设置为两个DataGridview控件的DataSource

2.在传输任何行时根据需要更改数据集

3.再次,从数据集设置更新表作为DataGridview控件的DataSource
First make sure that DataSource property is update for both DataGridView Controls using DATASET...

then on Button Click event.. transfer the Selected Row to DataSet where you want to move the record ...and ....then again update the DataSource Property of both DataGridView Controls...

Before update DataSource for second time... Don't forgot to DELETE the same Row from OLD table/Dataset of first DataGridView...


in simple steps...

1. Set Tables from Dataset as DataSource of both DataGridview controls
2. Make changes to Dataset as required while transferring any row(s)
3. Again, set update Tables from Dataset as DataSource of both DataGridview controls


这篇关于Datagridview在Windows窗体中编辑应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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