How can I change the visible limits of uidatepicker?

조회 수: 4 (최근 30일)
rmit
rmit 2019년 1월 15일
답변: Abhipsa 2025년 1월 30일
When using the datepicker component in AppDesigner I want to set the limits which each component presents to the user. In particular I want to be able to choose the year from a greater range than 40 years, which seems to be the default no matter what limits are set, when creating the datepicker component.
See this example:
function mydateapp
f = uifigure('Position',[340 400 415 300]);
d = uidatepicker(f,'DisplayFormat','MM-dd-yyyy',...
'Position',[130 190 150 22],...
'Value',datetime(2000,1,1),...
'Limits', [datetime([1960, 1, 1]), datetime([2040, 1, 1])],...
'ValueChangedFcn', @datechange);
end
  댓글 수: 1
rmit
rmit 2019년 1월 15일
Support has confirmed this is currently not possible. They might consider adding this functionality in a future release.

댓글을 달려면 로그인하십시오.

답변 (1개)

Abhipsa
Abhipsa 2025년 1월 30일
Hi, I get that you want the dropdown to show the years from “1960” to “2040”, but it’s showing a range of only 40 years. I am able to reproduce the issue in MATLAB R2024b and R2018b.
You can use this workaround that I have verified in 2024b and 2018b.
If you select any extreme value (highest or lowest) present in the given selection, then the dropdown gets extended up to next 40 years (depending on the values that has been selected).
The "Limits" parameter functions correctly, preventing selection beyond the specified bounds by crossing out the dates that are out of bound.
You can use "doc uidatepicker” command in your MATLAB command window to access the official documentation for “uidatepicker”.

카테고리

Help CenterFile Exchange에서 Calendar에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by