문제

I stored a date value and retrieve it and the format of the date in the string is yyMMdd. Now when the user loads that from the string i would like to select the DateTimePicker as the user loaded date.

Sample code:

string strDate = strRead.Substring(23, 6);
DateTime dt = DateTime.Parse(strDate);

Can any one give me an idea for the next?

도움이 되었습니까?

해결책

The most efficient way, I guess:

DateTimePicker p = new DateTimePicker();
DateTime result;
if (DateTime.TryParseExact("101025", "yyMMdd", CultureInfo.CurrentCulture, DateTimeStyles.None, out result))
{
    p.Value = result;
}

다른 팁

Do you mean

string strDate = strRead.Substring(23, 6);
DateTime dt = DateTime.Parse(strDate);
dateTimePicker.Value = dt;
dateTimePicker.Value = dt;
dateTimePicker.Focus(); //if by Select to meant to give it the focus
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top