有一个Form窗体有DataGridView控件
第二个窗体是数据编辑窗体,填写一些数据保存,可以在第一个窗体显示
当双击某一行时弹出第二窗体,进行数据编辑。
请问这样怎么实现?很急,谢谢!!!在线等

解决方案 »

  1.   

    private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
    {
        //e.RowIndex是行索引
         //.....
         Form2 form2=new Form();
         form2.Show();
    }
      

  2.   

    //form1
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;namespace WindowsFormsApplication1
    {
       public partial class Form1 : Form
       {
          public  string str = "";
          public Form1()
          {
             InitializeComponent();
          }      private void button1_Click(object sender, EventArgs e)
          {
             Form2 f = new Form2();
             f.ShowDialog(this);
             this.label1.Text  = str;
          }
       }
    }
    //form2
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;namespace WindowsFormsApplication1
    {
       public partial class Form2 : Form
       {
         public string str = "";
          public Form2()
          {
             InitializeComponent();
          }      private void button1_Click(object sender, EventArgs e)
          {
             Form1 f = (Form1)this.Owner;
             f.str = this.textBox1.Text;
             this.Dispose();
          }
       }
      

  3.   

    双击的时候给form1种的label赋上相应的值。
      

  4.   

    //单元格双击事件
    private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
    {
       //当前双击单元格所在的行号
       int myRow = dataGridView1.Rows[e.RowIndex];
       //当前要传入form2的ID号的单元格
       dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
    }
      

  5.   

    写错,int myRow多余,dataGridView1.Rows[e.RowIndex];是所在行
      

  6.   


    这个思路是正解.要编缉选中的行,可以传个ID过去.取完再把DGV刷新(把DGV当成参数传过去重置DGV,或DGV设成public重轩)即可!