2

My code is really too long to be posted here, even by little portions. So I will just ask for one or two things : It appears to me that when modifying the 'Data' property of an uitable 'ht' :

set(ht, 'Data', something);

that the "cellSelectionCallback" routine is triggered (as the selection is very likely to have changed, indeed), but not immediatly after the dataset is modified.

  1. Is this true ?
  2. Is there any way to prevent such a behavoir ?

Thanks !

Robert Seifert
  • 25,078
  • 11
  • 68
  • 113
embrouille
  • 43
  • 1
  • 6

3 Answers3

2

I have code using a uitable, e.g:

tbl = uitable('Parent', fh, 'CellSelectionCallback',{@cell_select_callback fh});

I did a quick experiment and when using set(tbl,'Data',my_data) the callback is triggered only if the set causes the selected cell(s) to change, and this happens immediately (as far as I can tell - I saw no appreciable delay).

To stop that happening you could just unset the CellSelectionCallback property, change the data, and then reset CellSelectionCallback.

Justin
  • 1,980
  • 1
  • 16
  • 25
  • Ok, so it didn't solved my problem (when resetting the cellSelectionCallback the callbacki is still called, in my program at least). I managed to avoid the problem using the setValueAt(val, row, col) method of the JTable attached to the uitable. This way the 'Data' property is not modified, and the callback function isn't triggered. Thanks for your help anyway. – embrouille Dec 14 '12 at 13:43
1

I had the same issue. Was getting index out of bounds warnings. To get rid of those I used this in my CallSelectionCallback:

if ~isempty(eventdata.Indices)
 // all the code
end

When the set command triggers the CallSelectionCallback the eventdata.Indices is empty.

Sébastien Renauld
  • 19,203
  • 2
  • 46
  • 66
1

A similar possibility to Sebastien's answer is to put this in your cellselectioncallback function:

function output = mycellselection(source,event)

if isempty(event.Indixes)
    output = [];
    return
end
% rest of your code for cell selection

end

If you don't have any output needed, you can just remove it. I just put it in there to remind you that you have to assign a value to any outputs.

Michelle
  • 31
  • 2