Deselect table cells
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi everybody, I have been working at a project for an exam.
My GUI is formed by 2 popup menu and one table. When I chose an option in the first popup menu, i get others fields in the second popup so that the first one is called CHAPTERS and the second one BLOCKS. Each chapter has specific blocks ( in particular not the same number... maybe the first chapter has 10 blocks or possible options that can be chosen, while the second chapter can have only 3 choices).
Now, when I chose a field in the second popup, i should obtain a list of names in the table. Then when I click over one name in the table, an edit-box is updated and shows the item selected. If I pick another item of the same view, or I might say of the same block I do not have any problem and the editbox is correctly updated. Instead, clicking on another block in the second popup, I get an error, but the table is updated correctly and I can chose the name.
It's strange, because the process works out. But I get an error in the CellSelection Callback. I think that the problem is when I change table, because the cell previously selected disappear.
Can anyone help me!!
I spent an entire day over this error...
Thanks.
1 comentario
Jan
el 12 de Sept. de 2011
Please post the complete error message and the relevant lines of code. We do not have crystalballs to guess such details.
Respuestas (4)
Ocram
el 13 de Sept. de 2011
1 comentario
Walter Roberson
el 13 de Sept. de 2011
I am not at all certain as I rarely use uitable(), but I think I might have read the the cell selection callback function is called upon initialization of the table, at a time when nothing is selected.
Your callback should check isempty(handles.selectedCells) and do something gracefully for that case.
Michael B
el 15 de Abr. de 2016
I know this was asked a long time ago, but just in case other folks (like myself) run into this problem in the future, I managed to figure out what was going on. When something causes the current table selection to be cleared, it automatically triggers the CellSelectionCallback function and runs any code inside. The eventdata.Indices variable that is generated by this action is a 0x2 double array. Performing an isempty check on eventdata.Indices directly will return 0 because it isn't empty; it's just an array of zero length. If anything within the CellSelectionCallback function uses the value of eventdata.Indices and doesn't have a way to handle a zero-length double array as input, MATLAB will throw an error. This can be avoided simply by adding a conditional statement inside the CellSelectionCallback function that checks the length of eventdata.Indices before doing anything else.
0 comentarios
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!