필터 지우기
필터 지우기

How can I restrict a editable uitable to only allow char input?

조회 수: 5 (최근 30일)
Johnny Birch
Johnny Birch 2018년 10월 5일
답변: Walter Roberson 2018년 10월 14일
I have a editable uitable which contain either char or numbers, but all as strings. See an example below. I allow the user to edit the content by the "uitable2_CellEditCallback function", but how can I restrict the input to allow only characters, and not numbers? If possible I want the GUI to throw a message saying something like: "Only characters allowed".
Here is a short example of the cell array represented in the uitable.
c = {
'# 2.537' '1.219' '0.457' '0.214' '# 0.120' '0.245'
'3.244' '# 1.400' '0.649' '0.515' 'X' '0.075'
'2.993' '1.282' 'X' '0.309' '0.140' '0.140'}
  댓글 수: 3
Walter Roberson
Walter Roberson 2018년 10월 13일
Digits entered into a uitable entry will be treated like any other character if the column format is char. Digits are characters. Are you trying to get it to accept all characters except the 0 through 9? How about Japanese digits?
Johnny Birch
Johnny Birch 2018년 10월 13일
Hi Kevin and Walter. I want to prevent the user from inserting numbers from 0-9. Everything else is acceptable.

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

답변 (1개)

Walter Roberson
Walter Roberson 2018년 10월 14일
1) You can mark the column as editable. Use a CellEditCallback to examine the user's input after they have pressed Return / Enter or clicked elsewhere, but before it has been saved, and modify the data before it is saved. The available information includes which cell is being edited. However, this does not work on a character-by-character basis.
2) You can use mark the column as not editable. Use CellSelectionCallback to take a record of which cell the user clicked on. Use KeyPressFcn callback to see which keys the user is typing, and have it selectively make changes to the content of the appropriate cell (including handling backspace for editing.) KeyPressFcn does not give information about where in the table the user clicked. This cannot be said to be a convenient way to handle the task. I do not recall at the moment what happens if you have a KeyPressFcn active on an editable cell: something similar is possible with uicontrol style 'edit', and that combination has oddities about when the characters stored by KeyPressFcn become available.
3) You can head over to http://undocumentedmatlab.com and read about the java internals of uitables and hope to find a suitable edit mechanism described there.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

제품


릴리스

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by