c# - DateTimePicker value from DataGridView -
i have textboxes , datetimepicker. there datagridview on it. upload data mysql table. want modify data via textboxes , datetimepicker, error:
system.argumentoutofrangeexception
on datetimepicker.value row:
private void datagridview1_selectionchanged(object sender, eventargs e) { datetimepicker1.value = convert.todatetime(datagridview1.selectedrows[0].cells[1].value); idotextbox.text = datagridview1.selectedrows[0].cells[2].value.tostring(); pkcombobox.text = datagridview1.selectedrows[0].cells[3].value.tostring(); minositesbox.text = datagridview1.selectedrows[0].cells[4].value.tostring(); esetextbox.text = datagridview1.selectedrows[0].cells[5].value.tostring(); fotextbox.text = datagridview1.selectedrows[0].cells[6].value.tostring(); megjegyzestextbox.text = datagridview1.selectedrows[0].cells[7].value.tostring(); }
what did wrong?
you don't have row selected, cell.
make sure have correct selectionmode property set:
datagridview1.selectionmode = datagridviewselectionmode.fullrowselect;
also, make sure have selected rows:
if (datagridview1.selectedrows.count > 0) { datetimepicker1.value = convert.todatetime(datagridview1.selectedrows[0].cells[1].value); // ... }
Comments
Post a Comment