Table data is not editable at this location, why won't this checkbox let me check it?

。_饼干妹妹 提交于 2019-12-11 12:05:36

问题


f = figure;
 columnname = {'X' , 'Y'};
 Selection = {'A','B','C','D','E'}
[vals{1:numel(Selection),1}]=deal(false)
    columnform = {'logical','logical'};
t = uitable('Data',vals,'ColumnName', columnname, 'ColumnFormat', columnform,'ColumnEdit',[true true true], 'RowName', Selection);

If you run this script it should spit out a figure. but i can only select the checkboxes in the X column of the table. Why is that?


回答1:


Tha's because the variable vals does not contain sufficient data to fill the table.

Simple replicate it to form a 2-column array and it works. i.e. add this line:

vals = [vals vals]

before creating the table.

Whole code:

f = figure;
close all
clc
clear

columnname = {'X' , 'Y'};
Selection = {'A','B','C','D','E'}
[vals{1:numel(Selection),1}]=deal(false);

vals = [vals vals]

columnform = {'logical','logical'};

t = uitable('Data',vals,'ColumnName', columnname, 'ColumnFormat', columnform, 'RowName', Selection,'ColumnEdit',true(1,2*size(Selection,1)));

Output:

EDIT:

To get indices of selected cells you don't need to specifically add new variables.

By setting the CellSelectionCallback you can fetch the indices directly.

Let's say you add this line after creating the table:

set(t,'CellSelectionCallback',@SelCB)

Then the function can be used to get indices as follows:

function SelCB(~, event)

    SelectedCells = event.Indices        
 end

Which will output a 1x2 element vector each time a cell is selected/deselected.



来源:https://stackoverflow.com/questions/29078437/table-data-is-not-editable-at-this-location-why-wont-this-checkbox-let-me-chec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!