c# - append new to gridcontrol devexpress -


i trying add new row datagridview button click learning purposes. when click button, deletes old data , add new row. want append grid

here form_load function gets data database , fill grid.

private void form1_load(object sender, eventargs e)     {         sqlconnection connection = new sqlconnection("data source=arif-bilgisayar;initial catalog=rotanetlocal;persist security info=true;user id=sa;password=12345");         sqldataadapter adapter = new sqldataadapter("select * testtable", connection);         dataset sourcedataset = new dataset();         adapter.fill(sourcedataset);         gridcontrol1.datasource = sourcedataset.tables[0];      } 

and here button event supposed append row grid, deletes old data , inserts new one

private void btn_update_click(object sender, eventargs e)     {         datatable dtoperation = new datatable();          var myoriginaldatasource = (datatable)gridcontrol1.datasource;         var dr = myoriginaldatasource.newrow();         dr["id"] = 1;         dr["name"] = "gelen havale";         dr["lname"] = "gelen havale";         dtoperation.rows.add(dr);          gridcontrol1.refresh();     } 

my btn_update_click function trying create row , append old data. crashes. says taht row belongs table. how can fix that?

you need change code this:

private void btn_update_click(object sender, eventargs e) {     var myoriginaldatasource = (datatable)gridcontrol1.datasource;     var dr = myoriginaldatasource.newrow();      dr["id"] = 1;     dr["name"] = "gelen havale";     dr["lname"] = "gelen havale";      gridcontrol1.refresh(); } 

i think worth spending time reading on object orientation principles

you still creating new datatable needlessly , adding row instance rather datatable data-bound grid control instance.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -