c# - How can I create a footer for cell in datagridview -


i need create datagridview cells have 2 parts. 1 part content of cell such 0, 1 etc value. , remain part footer of cell, footer of word document, refers ordinal number of cell.

i can not enclose images question may ambiguous.

anyways in advance.

enter image description here

to create datagridview cells content need code cellpainting event.

first set cells have enough room content , layout normal content wish..:

datagridview dgv = datagridview1;  // quick reference  font fatfont = new font("arial black", 22f); dgv .defaultcellstyle.font = fatfont; dgv .rowtemplate.height = 70; dgv .defaultcellstyle.alignment = datagridviewcontentalignment.topcenter; 

next fill in content; add content cells' tags. more complicated things more fonts etc, want create class or stucture hold it, maybe in tags..

dgv.rows.clear(); dgv.rows.add(3);  dgv[1, 0].value = "na"; dgv[1, 0].tag = "natrium"; dgv[1, 1].value = "fe"; dgv[1, 1].tag = "ferrum"; dgv[1, 2].value = "au"; dgv[1, 2].tag = "aurum"; 

here example of coding cellpainting event:

private void datagridview1_cellpainting(object sender,                 datagridviewcellpaintingeventargs e) {     if (e.rowindex < 0) return;  // header? nothing do!     if (e.columnindex == yourannotatedcolumnindex )     {         datagridviewcell cell = datagridview1[e.columnindex, e.rowindex];         string footnote = "";         if (cell.tag != null) footnote = cell.tag.tostring();          int y = e.cellbounds.bottom - 15;  // pick  font height          e.paintbackground(e.clipbounds, true); // show selection? why not..         e.paintcontent(e.clipbounds);          // normal content         using (font smallfont = new font("times", 8f))             e.graphics.drawstring(footnote, smallfont,               cell.selected ? brushes.white : brushes.black, e.cellbounds.left, y);          e.handled = true;     } } 

for longer multiline footnotes can use bounding rectangle instead of x&y coordinates..


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -