日期:2014-05-17  浏览次数:20735 次

DataGridView点击某行,弹出一个新窗口,在新窗口操作后,返回一个值(或多值)到DataGridView的行.
DataGridView点击某行,弹出一个新窗口,在新窗口操作后,
返回一个值(或多值)到DataGridView的行.
这样应该怎么做??

------解决方案--------------------
假如新窗口是Form2,它有两个属性,p1,p2都是文本,代表返回的值。

Form2 frm = new Form2();
if (f.ShowDialog(this) == DialogResult.OK)
{
更新选中行的值,选中行可以通过CurrentRow得到
datagridview1.Rows[datagridview1.CurrentRow].Cells[列号].value=frm.p1;
}
------解决方案--------------------
Form1:
 DataSet ds = new DataSet();
private void dataGridView1_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
int r = e.RowIndex;
// DataRow dr = ds.Tables[0].Rows[e.RowIndex];
Form2 fr = new Form2(ds, r);
fr.Show();
}
Form2:
DataSet ds1= new DataSet();
int r1;
public Form2(DataSet ds2,int r2)
{
ds1 = ds2;
r1 = r2;
InitializeComponent();
}

private void Form2_Load(object sender, EventArgs e)
{
DataRow dr = ds1.Tables[0].Rows[r1]; 

textBox1.Text = dr[0].ToString();
}
}
这是传值,修改更新在Form2中ds1中就行!!!