winforms - C# dataGridView shows no data -


there many posts this, no 1 helped me. maybe have logical problem or this. i'am c# newbie.

so following problem. have datagridview in form1. when click button1 form6 appears, give in table name , filldatagrid-mehtod runs in form1. but. shows no data datagradview keeps empty nothing in it.

now curios thing, if place code filldatagrid-method in button1 method every thing works fine.

database (sqlite) connection works fine (not shown in code example).

form1:

private void button1_click(object sender, eventargs e) {     form6 f6 = new form6();     f6.show(); }  private void button3_click(object sender, eventargs e) {     form3 createtable = new form3();     createtable.show();          }  public void filldatagrid(string eingabe) {     string tabelle = eingabe;                    string selectcommand = "select id, von, bis, dauer, kommentar " + tabelle + ";";      sqlitedataadapter dataadapter = new sqlitedataadapter(selectcommand, sqlite_conn);     dataset ds = new dataset();     dataadapter.fill(ds);     //datagridview1.databindings.clear();     //datagridview1.columns.clear();      datagridview1.autogeneratecolumns = true;     datagridview1.datasource = ds.tables[0].defaultview; } 

form6:

private void button1_click(object sender, eventargs e) {     form1 f1 = new form1();     string eingabe = textbox5.text;      f1.filldatagrid(eingabe);     hide(); } 

you never show form:

form1 f1 = new form1(); 

so there's nothing display. if want display grid on already existing form need use that one, not new one.

since form6 has dependency on instance of form1, require dependency in constructor:

private form1 form1instance { get; set; }  public form6(form1 form1instance) {     form1instance = form1instance; } 

then when create instance of form6, supply dependency:

form6 f6 = new form6(this); f6.show(); 

then in form6 can use instance show grid:

string eingabe = textbox5.text; form1instance.filldatagrid(eingabe); hide(); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -