首先说明一下:我有2个窗体。
主窗体DataGridView里显示数据(id,name,age)等。
1   111  张三  12
2   112  李4   13
第2窗体上显示(3个列字段)第一列数据是主窗体的列名,第2列是列名中文的别名,第3列是checkbox列 用来选择。
就是这样显示
1  id  id号 checkbox
2  name 名字 checkbox
3  age  年龄 checkbox
当我勾第一个、第三个checkbox的时候
第一个窗体就显示id 和 age列。第2窗体数据绑定 如何实现比较好?checkbox 列点击事件怎么写的?谢谢
 
 

解决方案 »

  1.   

    在checkbox事件里传值给父窗体,重新绑定数据
    string s="";
     private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
            {
                if (this.dataGridView1.Columns[e.ColumnIndex].Name.Equals(""))
                {
                    DataGridViewCheckBoxCell dgvCheckBoxCell = this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex] as DataGridViewCheckBoxCell;
                    s=dataGridView1.Rows[e.RowIndex].Cells[""].Value;
                }
            }
    public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        public string TextBox1Text
            {
                set { this.textBox1.Text = value; }
                get { return this.textBox1.Text;  }
            }        private void button1_Click(object sender, EventArgs e)
            {
                Form2 frm2 = new Form2();
                frm2.Show(this);
            }
        }    public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }
            private void button2_Click(object sender, EventArgs e)
            {
                Form1 frm1 = (Form1)this.Owner;
                frm1.TextBox1Text = this.textBox2.Text;
                this.Close();
            }
        }
      

  2.   

    我这是网吧,
    所以只能给你个思想啦,希望对你有用
    一、两个窗口需要一个通道!(比如在form1上放一个botton来实例form1并显示)
    二、从问题上看,两个窗口之间的离不开form1上的DataGridView.所以我们就把这个object通过实例化传到form2来.
    三、因为要接收form1传过来的值,所以我们就在form2构造带DataGridView参数的构造方法,这样我们就可以在form2上操作form1上的DataGridView
    四、在form2上按照传过来的DataGridView实例化一个DataTable,
    五、按楼上的做就可以了
      

  3.   

    http://www.180bbs.com/topictag-16.aspx都是GridView操作的实例
      

  4.   

    CellValueChanged 这个事件不好用啊。。有的选中没除法时间。
      

  5.   

    cellvaluechange还是比较好用的。
      

  6.   

    我是按确定按纽 把整个DataGridview 传出去。再遍历出去获取??