2

I have Uitable with data read from a AScii file.

  1. I want to select columns using mouse and also using checkboxes. I tried a lot but i cannot figure out how to select uitable column using mouse and getting that data.

  2. Also I am trying to insert checkbox in the last row of the uitable, so when user selects checkbox, particular column is selected.

Any idea?

Robert Seifert
  • 25,078
  • 11
  • 68
  • 113
Satya Vamsi
  • 217
  • 3
  • 6
  • 13

2 Answers2

3

To handle clicks on the column headers, one must go to undocumented territory:

%# old UITABLE (based on Swing JTable, instead of the new JIDE-based)
[hTable,hContainer] = uitable('v0', 'Parent',gcf, ...
    'Data',magic(7), 'ColumnNames',cellstr(num2str((1:7)','C%d'))');
set(hContainer, 'Units','normalized', 'Position',[0 0 1 1])

%# handle mouse clicks on table headers
jTableHeader = hTable.getTable().getTableHeader();
h = handle(jTableHeader, 'CallbackProperties');
set(h, 'MousePressedCallback',...
    @(src,evt) disp( src.columnAtPoint(evt.getPoint())+1 ))  %# zero-based index

screenshot

Amro
  • 123,847
  • 25
  • 243
  • 454
2

You should edit the CellSelectionCallback and the CellEditCallback properties of your table.

   set(myTable,`CellSelectionCallback`,@CallBack)

In order to see what columns/rows were selected, use the event data that you receive in your callback.

  function CallBack(hObj,evt)   
      disp(evt);
  end

As far as I know, there is no way to discover what columns are currently selected when the callback is not fired.

Andrey Rubshtein
  • 20,795
  • 11
  • 69
  • 104
  • Hello Andrey, Thanks for your response. When i followed your instructions i was getting indices, but i want to get the data instead of indicies. – Satya Vamsi Jun 19 '12 at 15:06
  • @SatyaVamsi, getting the data is much easier - use get(myTable,'Data'). Filter it by the indexes in evt – Andrey Rubshtein Jun 19 '12 at 15:07
  • I trying to filter the data, but i was getting wrong data, Could you please help me how to get selected data – Satya Vamsi Jun 21 '12 at 20:08