I have a WinForm with a DateTimePicker control on it showing a specific date from my SQL database.
When the user clicks it, I have a custom form open to ask if they are sure they want to change the date.
If they click OK they can proceed to change the date using the DateTimePicker and the changes are posted back to my SQL Server database.
If the user clicks Cancel instead, the method exits so no changes are saved to the database.
However, what is annoying me, is even when the user clicks Cancel, the DateTimePicker drop down calendar stays open, which a user may interpret as the action having failed to Cancel. How can I get the DateTimePicker to close an open drop down calendar?
private void datDOA_ValueChanged(object sender, EventArgs e)
{
frmConfirmBox frmCB = new frmConfirmBox("Are you sure you want to change the Date of Accident?");
frmCB.ShowDialog();
if (frmCB.intButton == 0)
{
return;
}
datDOA.Format = DateTimePickerFormat.Long;
//...Connect to Database...//
string strCaseNo = txtCaseNo.Text;
string strConnect = BuildConnectionString();
SqlConnection linkToDB = new SqlConnection(strConnect);
linkToDB.Open();
//...Send User Input to Database...//
DateTime dateNewDate = datDOA.Value;
string commandText = "UPDATE tblCases SET DOA = @DOAVal WHERE CaseNo = @CaseNoVal;";
SqlCommand sqlCom = new SqlCommand(commandText, linkToDB);
sqlCom.Parameters.Add("@DOAVal", SqlDbType.DateTime);
sqlCom.Parameters.Add("@CaseNoVal", SqlDbType.VarChar);
sqlCom.Parameters["@DOAVal"].Value = dateNewDate;
sqlCom.Parameters["@CaseNoVal"].Value = strCaseNo;
sqlCom.ExecuteNonQuery();
linkToDB.Close();
}