Monday 15 February 2010

winforms - C# prevent same combobox column in datagridview from being autogenerated -



winforms - C# prevent same combobox column in datagridview from being autogenerated -

in winform application i'm adding combobox column in datagridview using next code:

dgvloadtable.datasource = null; crudloaddata(0); //calls function load info in datagridview , recordnum //set 0 showing header in dgvloadtable dgvloadtable.readonly = false; dgvloadtable.allowusertoaddrows = true; datagridviewcomboboxcolumn cboisnew = new datagridviewcomboboxcolumn(); int i= dgvloadtable.columns["columnname"].index; dgvloadtable.columns.insert(i, dgvcol); dgvloadtable.columns[i].headertext = dgvloadtable.columns[i + 1].headertext; dgvloadtable.columns[i + 1].visible = false;

this code executed under treeview_nodemouseclick event.now works fine first time click on node. sec time keeps adding added column @ first column index of datagridview. because, i'm rebinding columns except cboisnew (that been added grid), became first , other columns datagridview source re-added @ end.

how can overcome problem? tried checking if column exists couldn't solve it.fyi, info source entity model.

the solution easy. before loading info datagridview write next line:

datagridviewname.columns.clear();

in case:

dgvloadtable.columns.clear();

c# winforms datagridview combobox

No comments:

Post a Comment