c# - When formatting floats in DataGridView to a certain decimal, cannot copy full number -


i'm creating windows form application, more or less acting interface sql db our users. want format floats 1 or 2 decimal places when @ form, want have ability copy datagridview out excel full float if desire.

for example, if i'm formatting rows percent 1 decimal place i'll use

datagridview1.rows[i].defaultcellstyle.format = "p1"; 

this looks great in form, when copy datagridview clipboard, copies 1 decimal place, if float datatable i'm using source has more decimal places.

i'm having trouble figuring out how copy unformatted data clipboard. i've considered making copy button accesses invisible datagridview unformatted, i'd users able ctrl-c visible, formatted datagridview.

any ideas? letting me know i'm out of luck help, i'll give on ctrl-c functionality , create separate copy function. thanks.

it impossible allow users copy different being displayed (1-decimal values). workaround want might enabling 2 different "modes" show information in cells: short , long format. , adding user-friendly way switch between both modes; example: pressing "enter" in cell. sample code:

private void datagridview1_keydown(object sender, system.windows.forms.keyeventargs e) {     if (e.keycode == keys.enter)     {         if (shortmode)         {             datagridview1.rows[currow].defaultcellstyle.format = ""; //number decimals             shortmode = false;         }         else         {             datagridview1.rows[currow].defaultcellstyle.format = "p1"; //number percentage 1 decimal             shortmode = true;         }     } } 

where shortmode boolean variable declared globally , currow row want change.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -