Cell select callback on uitable

26 ビュー (過去 30 日間)
Jason
Jason 2014 年 12 月 17 日
I have a uitable that I want to be able to select a cell with a mouse, and the value in that cell be put in an edit box. Under the CellSelectionCallback, I have the following code.
However, it attempts to run (and crash) when the contents of the uitable change. How can I only implement this when the mouse selects that cell?
function uitable1_CellSelectionCallback(hObject, eventdata, handles)
% hObject handle to uitable1 (see GCBO)
% eventdata structure with the following fields (see MATLAB.UI.CONTROL.TABLE)
% Indices: row and column indices of the cell(s) currently selecteds
% handles structure with handles and user data (see GUIDATA)
%handles=guidata(source);
handles.currentCell=eventdata.Indices;
guidata(gcf,handles);
handles=guidata(gcf);
Indices=handles.currentCell;
data=get(handles.uitable1,'Data');
data=data(Indices(1),Indices(2));
set(handles.editNum,'String', data);
  5 件のコメント
Jason
Jason 2014 年 12 月 19 日
Thankyou Geoff, I've included another check before executing this:
if ~isempty(eventdata.Indices)&&~isempty(data)
Geoff Hayes
Geoff Hayes 2014 年 12 月 19 日
Cool, Jason. Consider making your solution (in the above comment) as an answer to your question.

サインインしてコメントする。

採用された回答

Jason
Jason 2014 年 12 月 22 日
編集済み: Jason 2014 年 12 月 22 日
Thankyou Geoff for the help, I've included another check before executing this:
if ~isempty(eventdata.Indices)&&~isempty(data)
if ~isempty(eventdata.Indices)
handles.currentCell=eventdata.Indices;
guidata(hObject,handles);
Indices=handles.currentCell;
data=get(handles.uitable1,'Data');
data=data(Indices(1),Indices(2));
set(handles.editNum,'String', data);
end
  1 件のコメント
Julius Rinaldi Simanungkalit
Julius Rinaldi Simanungkalit 2020 年 9 月 7 日
this method does work, but only to display one cell only. can you help me how to display one table row, by just clicking. Please help me :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFunction Creation についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by