c# - How to pass data from childform to parentform -
i have 2 forms ,form1 , form2.
form1 - parent form2 - child
form1 contains following,
textbox - loads file path, datagridview - loads file data, buttonnext -when button cliked opens form2,
form2 contains following,
browsebutton - broswe file directory textbox - shows path buttonfinish - tabes form1
*now want access datagridview form1(parent) form2(child). can broswe file on form2 , when click finish can see file path on form1(parent) textbox no databeing loaded.
how can load data on form1 datagridview ?
this code far..
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 grid form1 string pathselection = ""; if (txtinputfile.text.length > 0) { pathselection = txtinputfile.text; } odataset = new dataset(); xmlreadmode omode = odataset.readxml(pathselection); (int = 0; < 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 can handle gridview here public void loadgrid(string loadgrid) { gridview_input.tostring(); }
first things first. please avoid duplicate posts.
what variable _grid doing here ?? way of passing data 1 form other looks strange. nevertheless, tried simulate problem , able add rows in form1 from2. code listing given below. thing note,i have added 4 columns in datagridview in designer. in case might want add columns programmatically.
public partial class form2 : form { public form2(form1 frm1) { initializecomponent(); form1prop = frm1; } private void button1_click(object sender, eventargs e) { form1prop.setfilepath("hihi"); form1prop.datagridpropgrid.rows.add("hih", "ki", "lo", "po"); } public form1 form1prop { get; set; } } public partial class form1 : form { public form1() { initializecomponent(); } private void button1_click(object sender, eventargs e) { form2 frm2 = new form2(this); frm2.show(); } public void setfilepath(string filepath) { textbox1.text = filepath; } public datagridview datagridpropgrid { { return datagridview1; } } }
cheers
Comments
Post a Comment