Effacer les filtres
Effacer les filtres

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

5 vues (au cours des 30 derniers jours)
Johnny Birch
Johnny Birch le 5 Oct 2018
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 commentaires
Walter Roberson
Walter Roberson le 13 Oct 2018
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 le 13 Oct 2018
Hi Kevin and Walter. I want to prevent the user from inserting numbers from 0-9. Everything else is acceptable.

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 14 Oct 2018
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.

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Tags

Produits


Version

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by