如何将项目从一个gridview移动到另一个gridview? [英] How do I move items from one gridview to another gridview?

查看:158
本文介绍了如何将项目从一个gridview移动到另一个gridview?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个gridview,当用户在第一个gridview上突出显示一行并点击一个按钮时,它应该移动到第二个gridview。

I have two gridviews, and when the user highlights a row on the first gridview and clicks a button, it should move to the second gridview.

当我点击在记录被添加的按钮上,但它只添加我选择的最后一行(如果我选择了20行,只添加了最后一行)。

When I click on the button that record gets added but it only add the last row I've selected (if I select 20 rows, only the last gets added).

所有记录应该被移动。

我如何在ASP.NET中执行此操作?

How do I do this in ASP.NET?

推荐答案

private void button1_Click_1(object sender, EventArgs e)
{
    DataGridViewRow dr = dataGridView1.SelectedRows[0];

    dtItems.Columns.Add("city_ID");
    dtItems.Columns.Add("city_Name");
    dtItems.Columns.Add("status");
    dtItems.Columns.Add("date");

    if (dataGridView1.Rows.Count > 1)
    {
        for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
        {
            if (dataGridView1.Rows[i].Cells[0].Value != null)
            {
                DataRow row;
                row = dtItems.NewRow();

                row["city_ID"] = dataGridView1.Rows[i].Cells[1].Value.ToString();
                row["city_Name"] = dataGridView1.Rows[i].Cells[2].Value.ToString();
                row["status"] = dataGridView1.Rows[i].Cells[3].Value.ToString();
                row["date"] = dataGridView1.Rows[i].Cells[4].Value.ToString();

                dtItems.Rows.Add(row);
            }
        }
    }

    Form2 frm = new Form2(dtItems);
    frm.ShowDialog();
}

在Form2中复制这段代码:

In Form2 copy this code:

public Form2(DataTable dtIt)
{
    dtItems = dtIt;
    InitializeComponent();
}

private void AddEmptyRows()
{
    for (int i = 1; i <= 5; i++)
    {
        dataGV.Rows.Add();
    }
}

private void Form2_Load(object sender, EventArgs e)
{
    AddEmptyRows();

    for (int i = 0; i < dtItems.Rows.Count; i++) {
        dataGV.Rows[i].Cells[0].Value = dtItems.Rows[i]["city_ID"];
        dataGV.Rows[i].Cells[1].Value = dtItems.Rows[i]["city_Name"];
        dataGV.Rows[i].Cells[2].Value = dtItems.Rows[i]["status"];
        dataGV.Rows[i].Cells[3].Value = dtItems.Rows[i]["date"];
    }

    dataGV.Enabled = true;
}

这篇关于如何将项目从一个gridview移动到另一个gridview?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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