1

I want my uitable to have checkboxes that you can click in it. If I do it this way, i get the warning: Table data is not editable at this location.

As it is now, the boxes appear but you can't click them.

 p=figure
 D={'1', '2', '3' ,'4', '5','6'
    '7', '8', '9', '10', '11' ,'12'}
 data=D(:,1)
cnames={'', 'Left', 'Right','P1', 'P2', 'P3'}

table_resultat_nip=uitable('position',[0 200 500 200],...
   'parent',p,...
   'columnname', cnames,...
   'rowname', '',...
   'data',data,...
   'ColumnFormat',{'char','logical','logical','logical','logical','logical'},...
   'columneditable',[false, true, true, true, true, true])   ;
Machavity
  • 30,841
  • 27
  • 92
  • 100
  • I can't reproduce your problem, your code looks alright. Please modify your question and include runable code one can just copy&paste to try it out. Means, include example data and declare all needed variables. – Robert Seifert Jul 15 '14 at 10:08
  • ok edited it so you can just copy paste it! – user3796906 Jul 15 '14 at 10:23

1 Answers1

1

The data of the cells you want to edit need to be in the correct format.

There are two issues:

1)

data = D(:,1);

I understand you just want to use the data of the first column, but you need to declare the other columns as well, as locicals.

2)

Your data does not fit the columnformat, so rather use:

D = {'1', false, false ,false, false, false; ...
     '7', false, false, false, false, false};

Solution:

D = {'1', '2', '3' ,'4', '5','6' ;
     '7', '8', '9', '10', '11' ,'12'};


data = [ D(:,1)  num2cell( false( size(D,1) , size(D,2)-1) ) ];
%// where the -1 depends on how many "real" data columns you have.

or more generic:

N = 1;   %// Number data columns to keep
data = [ D(:,1:N)  num2cell( false( size(D,1) , size(D,2)-N) ) ];

All in all, the following code works, now you need to apply it to your case:

p = figure;

D = {'1', '2', '3' ,'4', '5','6' ;
     '7', '8', '9', '10', '11' ,'12'};

data = [ D(:,1)  num2cell( false( size(D,1) , size(D,2)-1) ) ];

cnames = {'', 'Left', 'Right','P1', 'P2', 'P3'};

table_resultat_nip=uitable('position',[0 200 500 200],...
   'columnname', cnames,...
   'rowname', '',...
   'data',data,...
   'ColumnFormat',{'char','logical','logical','logical','logical','logical'},...
   'ColumnEditable',[false, true, true, true, true, true]...
   );

Regarding the comment:

Okay, an even more generic case:

N = 1;   %// Number data columns to keep
M = 5;   %// Number of checkboxes desired

data = [ D(:,1:N)  num2cell( false( size(D,1) , M) ) ];
Robert Seifert
  • 25,078
  • 11
  • 68
  • 113
  • I get my data from another table where you can add new rows. Is there a way to set the data for this table so that I just get the first column from the old one and get checkboxes in the new one? – user3796906 Jul 15 '14 at 11:07
  • It works for the first 3 checkboxes, the fourth and the fifth i get the Warning: Table data is not editable at this location. The table that i import my data from is 4 columns, does this have to do anything with this? anyways, thanks for all the help you have given me so far! – user3796906 Jul 15 '14 at 11:26
  • Well I assumed your data has the same number of columns as your table, as in your example. Have a look at the last edit. Please also accept the answer if it finally solved your problem. Thanks! – Robert Seifert Jul 15 '14 at 11:31