我有两种形式,Form1和Form2。如何将数据从子窗体传递给父窗体
Form1中 - 家长 窗体2 - 儿童
Form1中包含以下,
文本框 - 它加载的文件路径, 的DataGridView - 加载其数据的文件, ButtonNext - 当按钮cliked它打开窗体2,
窗体2包含以下,
BrowseButton - 它从目录broswe的文件Textbox - 它然后显示路径 ButtonFinish - 它会将您重新映射到Form1
*现在我想从Form2(子)从Form1(父)访问datagridview。现在我可以broswe Form2上的文件,当我点击完成时,我可以看到我的文件路径Form1(父)从文本框,但没有databeing加载。
如何将Form1上的数据加载到datagridview中?
这是我的代码到目前为止..
Form2。
public frmInputFile(frmMain_Page _frmMain)
{
InitializeComponent();
this._frmMain = _frmMain;
}
private void btnBrowse_Click(object sender, EventArgs e)
{
BrowseFile();
}
private void btnFinish_Click(object sender,EventArgs e)
{
_frmMain.SetFilepath(txtInputfile.Text);
_grid.Rows.Clear(); //cant get the grid from form1
string PathSelection = "";
if (txtInputfile.Text.Length > 0)
{
PathSelection = txtInputfile.Text;
}
oDataSet = new DataSet();
XmlReadMode omode = oDataSet.ReadXml(PathSelection);
for (int i = 0; i < oDataSet.Tables[2].Rows.Count; i++)
{
string comment = oDataSet.Tables["data"].Rows[i][2].ToString();
string font = Between(comment, "[Font]", "[/Font]");
string datestamp = Between(comment, "[DateStamp]", "[/DateStamp]");
string commentVal = Between(comment, "[Comment]", "[/Comment]");
string[] row = new string[] { oDataSet.Tables["data"].Rows[i][0].ToString(), oDataSet.Tables["data"].Rows[i][1].ToString(), font, datestamp, commentVal };
_grid.Rows.Add(row);
}
this.Hide();
Program._MainPage.Show();
Form1中
private void btnLoadfile_Click(object sender, EventArgs e)
{
frmInputFile frmInput = new frmInputFile(this);
frmInput.Show();
}
public void SetFilepath(string Filepath)
{
txtInputfile.Text = Filepath;
}
//I dont know how i can handle the gridview here
public void Loadgrid(string LoadGrid)
{
Gridview_Input.ToString();
}
可能重复http://stackoverflow.com/questions/4887820/how-do-you-通过对象从窗体1到窗体2和回到窗体1) – Dmitry 2015-04-01 12:55:05
它看起来重复,但不同的问题 – prosts 2015-04-01 12:57:35