winforms - Datagrid view in Windows Form C# -


hello using datagridview in c# windows form , in data grid view using data grid link columns, example code here

  datagridviewlinkcolumn editlink = new datagridviewlinkcolumn();             editlink.usecolumntextforlinkvalue = true;             editlink.headertext = "edit";             editlink.datapropertyname = "lnkcolumn";             editlink.linkbehavior = linkbehavior.systemdefault;             editlink.text = "edit";             gvjobs.columns.add(editlink); 

and gives me output enter image description here

its fine when reload grid gives doesnot remove existing edit column giving data source null. example code , output here.

 gvjobs.datasource = null;             var jobs = (from v in general.ent.jobs                         (v.mrnumber == (string)txtmrnumber.text)                         select new                         {                             mrnumber = v.mrnumber,                             numberofdocuments = v.noofdocuments,                             pagenumbers = v.pagenumbers,                             jobstatus = v.job_status,                             scannertype = v.scanner_type,                             documenttype = v.documenttype.document_name,                             createddate = v.received_date                          }).tolist();             gvjobs.datasource = jobs;             datagridviewlinkcolumn editlink = new datagridviewlinkcolumn();             editlink.usecolumntextforlinkvalue = true;             editlink.headertext = "edit";             editlink.datapropertyname = "lnkcolumn";             editlink.linkbehavior = linkbehavior.systemdefault;             editlink.text = "edit";             gvjobs.columns.add(editlink); 

and output enter image description here

i want image 1 output after reloading grid.

you either have remove column while reloading grid or avoid adding column grid while reloading it.

you use

gvjobs.columns.remove() 

inorder remove edit column

or

for (int j=0;j<gvjobs.columns.count ;j++) {     if (gvjobs.columns[j].headertext == "edit")     {              datagridviewlinkcolumn editlink = new datagridviewlinkcolumn();          editlink.usecolumntextforlinkvalue = true;          editlink.headertext = "edit";          editlink.datapropertyname = "lnkcolumn";          editlink.linkbehavior = linkbehavior.systemdefault;          editlink.text = "edit";          gvjobs.columns.add(editlink);      }    } 

i hope helps out.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -