c# - Data from another class cannot be put to a datagridview -
good day. have passed data variable 1 class put datagridview in main form. put message boxes in each case know accesses said function , data passed. when run program. table doesn't put data inside it.
here code when pass data
if (txtcode1.elementat(intctr + 1).equals(val4)) { messagebox.show("lol"); compilourdes_gui cmp = new compilourdes_gui(); cmp.addtotbllexeme(val2, val2); break; } and here code of addtotbllexeme
public void addtotbllexeme(string lexeme, string token) { messagebox.show(lexeme+" "+token); tbllexeme.rows.add(lexeme , token); //adding tokens , lexeme table } code made datatable
private void start() { tbl1.autogeneratecolumns = true; tbl1.datasource = null; tbl1.rows.clear(); inittable(); string txtcode1 = txtcode.text; lexicalanalyzer lex = new lexicalanalyzer(txtcode1); lex.startlex(); tbl1.datasource = tbllexeme; } public void inittable() { tbllexeme = new datatable(); tbllexeme.columns.add("lexeme", typeof(string)); tbllexeme.columns.add("token", typeof(string)); } datatable tbllexeme = new datatable(); here image of output
. "test" word/s should inside table, can see, didn't put in.
ok think understand problem. if added columns directly in designer, guess added unbound columns. if so, datagridview cannot match row adding rows in table. fix this, delete columns datagridview. make sure datagridview has property autogeneratecolumns = true, before setting datasource = tbllexeme. 2 things happen automatically: firstly datagridview picks columns datatable; , secondly, when adding new row datatable, should show automatically in datagridview.
in addtotbllexeme, testing purposes, can please add, in place of rows.add():
datarow nr = tbllexeme.newrow(); nr[0] = lexeme; nr[1] = token; tbllexeme.rows.add(nr); then in debugger check nr have itemarray 2 columns.
Comments
Post a Comment