c# - datatimepicker visualstudio casting -
i'm trying put content of datetime cell datatimepicker. works way did cells value not when cells empty. code did :
if(dategridview1.rows[selectedrow].cells[2].value.tostring() != "null") datetimepicker1.value = (datetime)dategridview1.rows[selectedrow].cells[2].value;
when click on empty cells error shown : http://i.gyazo.com/273416fc2c2975fdf8902ad9bbb4caca.png
here proprieties of datatimeicker : http://i.gyazo.com/0296eef11d258823904a4db0db379c04.png
thanks
how trying string.isnullorempty()? if not null or empty, check range values. if ranges ok, put value on control.
if(!string.isnullorempty(dategridview1.rows[selectedrow].cells[2].value.tostring()) { datetime datetime = dategridview1.rows[selectedrow].cells[2].value; if (datetime > datetimepicker1.minvalue && datetime < datetimepicker1.maxvalue) { datetimepicker1.value = (datetime)dategridview1.rows[selectedrow].cells[2].value; } }
Comments
Post a Comment