Thread Subject: uitable - checkbox column callback

Subject: uitable - checkbox column callback

From: Nick Denman

Date: 15 Oct, 2008 03:39:01

Message: 1 of 3

Hi

I am trying to implement a logic between two columns in a uitable (R2007A - undocumented) where if the checkbox is clicked in one column, the checkbox in the other column is unchecked. I have tried implementing this using the DataChangedCallback and examples from Yair Altman on how to ensure that the callback does not enter an infinite loop. Unfortunately I have not been successful and the two checkboxes continually flicker when one is pressed and the callback does not end.

I have included the function used in the uitable's DataChangedCallback below. The checkbox columns are columns 11 and 12 (java-based index). Any suggestions would be greatly appreciated.

Cheers, Nick

%-----------------------------------------------------------
function checkboxCallback(mtable,eventdata)

if ~ishandle(mtable)
    return;
end

if ~isempty(getappdata(mtable,'inCallback'))
    return;
end

setappdata(mtable,'inCallback',1);

eventDetails = eventdata.getEvent;
col = eventDetails.getColumn;
row = eventDetails.getFirstRow;
if row >= 0 && col >= 11 && col <= 12
    mtable.getTable.setValueAt(true,row,col);
    mtable.getTable.setValueAt(false,row,11+doubl(col==11));
end

setappdata(mtable,'inCallback',[]);

Subject: uitable - checkbox column callback

From: SLt

Date: 15 Oct, 2008 07:55:55

Message: 2 of 3

On Oct 15, 5:39 am, "Nick Denman"
<ngdenmanNOS...@gmail.REMOVETHIS.com> wrote:
> Hi
>
> I am trying to implement a logic between two columns in a uitable (R2007A - undocumented) where if the checkbox is clicked in one column, the checkbox in the other column is unchecked. I have tried implementing this using the DataChangedCallback and examples from Yair Altman on how to ensure that the callback does not enter an infinite loop. Unfortunately I have not been successful and the two checkboxes continually flicker when one is pressed and the callback does not end.
>
> I have included the function used in the uitable's DataChangedCallback below. The checkbox columns are columns 11 and 12 (java-based index). Any suggestions would be greatly appreciated.
>
> Cheers, Nick
>
> %-----------------------------------------------------------
> function checkboxCallback(mtable,eventdata)
>
> if ~ishandle(mtable)
> return;
> end
>
> if ~isempty(getappdata(mtable,'inCallback'))
> return;
> end
>
> setappdata(mtable,'inCallback',1);
>
> eventDetails = eventdata.getEvent;
> col = eventDetails.getColumn;
> row = eventDetails.getFirstRow;
> if row >= 0 && col >= 11 && col <= 12
> mtable.getTable.setValueAt(true,row,col);
> mtable.getTable.setValueAt(false,row,11+doubl(col==11));
> end
>
> setappdata(mtable,'inCallback',[]);

Hi

I've already code something like that. But instead of using a data
application and setappdata to know if your are in the callbak or not,
I reset the DataChangedCallback. And i was often forced to add some
pause in order Matlab to take in account the reset.


function checkboxCallback(mtable,eventdata)

% Reset the DataChangedCallbak
set(mtable, 'DataChangedCallback', '');

pause(0.1) % To be sure the DataChangedCallback was changed

% Make change using setValueAt
...

pause(0.1) % To be sure the setValueAt are finished

% Set the DataChangedCallback
set(mtable, 'DataChangedCallback', @checkboxCallback);


It's not very pretty but it works ...

SLt

Subject: uitable - checkbox column callback

From: Nick Denman

Date: 17 Oct, 2008 00:41:02

Message: 3 of 3

SLt <stephanie.lescarret@gmail.com> wrote in message <723eb209-547f-433a-9bdc-569ebb1d63e9@b38g2000prf.googlegroups.com>...
> On Oct 15, 5:39 am, "Nick Denman"
> <ngdenmanNOS...@gmail.REMOVETHIS.com> wrote:
> > Hi
> >
> > I am trying to implement a logic between two columns in a uitable (R2007A - undocumented) where if the checkbox is clicked in one column, the checkbox in the other column is unchecked. I have tried implementing this using the DataChangedCallback and examples from Yair Altman on how to ensure that the callback does not enter an infinite loop. Unfortunately I have not been successful and the two checkboxes continually flicker when one is pressed and the callback does not end.
> >
> > I have included the function used in the uitable's DataChangedCallback below. The checkbox columns are columns 11 and 12 (java-based index). Any suggestions would be greatly appreciated.
> >
> > Cheers, Nick
> >
> > %-----------------------------------------------------------
> > function checkboxCallback(mtable,eventdata)
> >
> > if ~ishandle(mtable)
> > return;
> > end
> >
> > if ~isempty(getappdata(mtable,'inCallback'))
> > return;
> > end
> >
> > setappdata(mtable,'inCallback',1);
> >
> > eventDetails = eventdata.getEvent;
> > col = eventDetails.getColumn;
> > row = eventDetails.getFirstRow;
> > if row >= 0 && col >= 11 && col <= 12
> > mtable.getTable.setValueAt(true,row,col);
> > mtable.getTable.setValueAt(false,row,11+doubl(col==11));
> > end
> >
> > setappdata(mtable,'inCallback',[]);
>
> Hi
>
> I've already code something like that. But instead of using a data
> application and setappdata to know if your are in the callbak or not,
> I reset the DataChangedCallback. And i was often forced to add some
> pause in order Matlab to take in account the reset.
>
>
> function checkboxCallback(mtable,eventdata)
>
> % Reset the DataChangedCallbak
> set(mtable, 'DataChangedCallback', '');
>
> pause(0.1) % To be sure the DataChangedCallback was changed
>
> % Make change using setValueAt
> ...
>
> pause(0.1) % To be sure the setValueAt are finished
>
> % Set the DataChangedCallback
> set(mtable, 'DataChangedCallback', @checkboxCallback);
>
>
> It's not very pretty but it works ...
>
> SLt

Hi SLt

Thank you for your suggestions. Unfortunately, it didn't fix the problem (now the callback is not firing) as I don't believe that the DataChangedCallback is being re-enabled during the call to the callback function.

Cheers, Nick

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
uitable Nick Denman 14 Oct, 2008 23:40:04
checkbox Nick Denman 14 Oct, 2008 23:40:04
datachangedcall... Nick Denman 14 Oct, 2008 23:40:04
rssFeed for this Thread

Contact us at files@mathworks.com