表格数据在此位置不可编辑,为什么我不能选中此复选框? [英] Table data is not editable at this location, why won't this checkbox let me check it?

查看:170
本文介绍了表格数据在此位置不可编辑,为什么我不能选中此复选框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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);

如果运行此脚本,它将吐出一个数字.但我只能选择表格X列中的复选框.为什么会这样?

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?

推荐答案

这是因为变量vals没有包含足够的数据来填充表.

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

简单地复制它以形成一个2列的数组,它可以工作.即添加此行:

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

vals = [vals vals]

在创建表之前.

整个代码:

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)));

输出:

要获取选定单元格的索引,您无需专门添加新变量.

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

通过设置CellSelectionCallback,您可以直接获取索引.

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

每次选择/取消选择一个单元格时,都会输出1x2的元素矢量.

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

这篇关于表格数据在此位置不可编辑,为什么我不能选中此复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆