Deselect table cells
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
Jan
2011-9-12
Please post the complete error message and the relevant lines of code. We do not have crystalballs to guess such details.
回答(4 个)
Ocram
2011-9-13
1 个评论
Walter Roberson
2011-9-13
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
2016-4-15
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!