//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(); } } }
{
//e.RowIndex是行索引
//.....
Form2 form2=new Form();
form2.Show();
}
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();
}
}
}
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
//当前双击单元格所在的行号
int myRow = dataGridView1.Rows[e.RowIndex];
//当前要传入form2的ID号的单元格
dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
}
这个思路是正解.要编缉选中的行,可以传个ID过去.取完再把DGV刷新(把DGV当成参数传过去重置DGV,或DGV设成public重轩)即可!