在商品信息窗口中有个datagridview,是商品信息表,里面有一列是选择框。
现在我要在采购订货单中的窗体中将在商品信息窗口中选中的那些项添加到
采购订货单中的datagridview数据表格中,如何实现?

解决方案 »

  1.   

    把选中的行取出来,放进一个datatable中去,然后再把datatable跟你那个采购订货单datagridview绑定。
      

  2.   

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Windows .Forms ;
    using System.Data;
    using System.Configuration;
    using System.Data.SqlClient;namespace Dataset4
    {
        class Program
        {
            class MyForm : Form
            {
                public DataGridView grid1;
                public DataGridView grid2;
                public MyForm()
                {
                    grid1 = new DataGridView();
                    grid1.Dock = DockStyle.Top;
                    grid2 = new DataGridView();
                    grid2.Dock = DockStyle.Top;
                    this.Controls.Add(grid1);
                    this.Controls.Add(grid2);
                }
            }      
            static void Main(string[] args)
            {
                string con = "Data Source=.;Initial Catalog=Northwind;Integrated Security=True";
                DataSet set = new DataSet();
                string sqlStr = "select * from Customers";
                SqlDataAdapter adapter = new SqlDataAdapter(sqlStr, con);
                adapter.Fill(set);           
                MyForm fm = new MyForm();
                fm.grid2.DataSource = set.Tables[0];//绑定datatable对象
                fm.ShowDialog();
            }
        }
    }
      

  3.   

    增加datagrid里的记录就可以了吧。
      

  4.   

    datagridview对象有许多的记录特征标志,有新添的,修改的,原始的,可以根据这些属性来找到你需要的记录然后通过循环把这些记录添加到指定的datagrid里。
    PS 怎么小梁也来转战C#了。哈哈。顶一个。
      

  5.   

    同意一楼的说法,构建Table 然后再绑定到DataGridView中,然后再显示出来
      

  6.   

    这两个datagridview在不同的窗口中,我是先把所有要选择的商品先选好,然后
    有一个按纽,但按下按纽后,这些选中的项就依次添加到另一个窗口的 datagridview
    中了,这个过程怎么实现????
      

  7.   

    在控件的事件中,用FindControl找到相应的checkbox,判断是否选中,进行相关操作。
      

  8.   

    我的代码,只能添加一个,如何才能添加多个呢?
    for(int i=0;i<dataGridView1.SelectedRows.Count;i++)
                    {
                        if(dataGridView1.SelectedRows[i].Cells[1].Value.ToString()!="0")//判断是否选中
                        {
                            selsql="select num,mainnum,name,danwei,ckprice,plcprice,guige from tb_goods where id="+dataGridView1.SelectedRows[i].Cells[0].Value.ToString()+"";                       
                        }
                        frmCGDD cgdd = (frmCGDD)this.Owner;
                        abd.BindDGV_Sel(cgdd.dataGridView1, seladd);
                    }