Question

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 !

Était-ce utile?

La solution

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.

Autres conseils

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.

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top