Table Widget Data Retrieval
To retrieve data from a table widget, use the GET_VALUE keyword to WIDGET_CONTROL. You can retrieve the entire contents of the table or the contents of either a standard or disjoint selection. The format of the variable returned by the GET_VALUE keyword depends on the type of data displayed in the table (see Table Widget Data Types) and the type of selection (see Table Widget Selection Modes).
Entire Table
To retrieve data from the entire table, use the following command:
WIDGET_CONTROL, table, GET_VALUE=table_value
where table is the widget ID of the table widget. The table_value variable will contain either:
- an array with the same dimensions as the table, with one element per table cell, if the table contains data of a single data type, or
- a vector of structures, with one structure per table row or column, if the table contains structure data.
Standard Selection
To retrieve data for a group of selected cells, use the following command:
WIDGET_CONTROL, table, GET_VALUE=selection_value /USE_TABLE_SELECT
where table is the widget ID of the table widget. In standard selection mode, the selection_value variable will contain either:
- an array with the same dimensions as the selection, with one element per selected cell, if the table contains data of a single data type, or
- a vector of structures, with one structure per selected row or column, if the table contains structure data.
Note: You can also set the USE_TABLE_SELECT keyword equal to a four-element array of the form [ left, top, right, bottom ] containing the zero-based indices of the columns and rows that should be selected.
To retrieve the list of selected cells, use the following command:
selected_cells = WIDGET_INFO(table, /TABLE_SELECT)
where table is the widget ID of the table widget. The selected_cells variable will contain a four-element array of the form [ left, top, right, bottom ] containing the zero-based indices of the columns and rows that are selected.
Disjoint Selection
To retrieve data for a group of selected cells, use the following command:
WIDGET_CONTROL, table, GET_VALUE=selection_value, /USE_TABLE_SELECT
where table is the widget ID of the table widget. In disjoint selection mode, the selection_value variable will contain either:
- a one-dimensional array of values, with one element per selected cell, if the table contains data of a single data type, or
- a structure, with one field per selected cell, if the table contains structure data.
Note: You can also set the USE_TABLE_SELECT keyword equal to a 2 x n element array of column/row pairs specifying the cells that should be selected.
To retrieve the list of selected cells, use the following command:
selected_cells = WIDGET_INFO(table, /TABLE_SELECT)
where table is the widget ID of the table widget. The selected_cells variable will contain 2 x n array of column/row pairs containing the zero-based indices of the selected cells.
Converting Between Cell List Formats
With the addition of the ability to create disjoint table selections in IDL 5.6, the format of the list of selected cells returned by WIDGET_INFO was altered to accommodate non-rectangular regions when disjoint selections are enabled. To preserve backwards-compatibility, the format of the list was not changed for tables using standard selection mode, which guarantees a rectangular selection region.
If your application allows the table widget to switch between standard and disjoint selection mode, or if you have selection-handling routines that can be used with tables in either mode, you may want to modify the rectangular selection values returned for standard selections to match the lists of cells returned for disjoint selections. The following is a template for such a utility function. It accepts a four-element array of the form [ left, top, right, bottom ] containing the zero-based indices of the columns and rows that are selected and converts it into a 2 x n array of column/row pairs containing the zero-based indices the selected cells.
FUNCTION Make_Cell_List, Selection_Vector
num_cells = (Selection_Vector[2]-(Selection_Vector[0]-1)) * $
(Selection_Vector[3]-(Selection_Vector[1]-1))
return_arr = intarr(2,num_cells)
n=0
FOR i=Selection_Vector[1], Selection_Vector[3] DO BEGIN
FOR j=Selection_Vector[0], Selection_Vector[2] DO BEGIN
return_arr(n)=j
return_arr(n+1)=i
n=n+2
ENDFOR
ENDFOR
RETURN, return_arr
END
With this function compiled, you could retrieve the four-element selection array from a standard selection and turn it into a 2 x n element array with the following commands:
selected_cells = WIDGET_INFO(table, /TABLE_SELECT)
cell_list = Make_Cell_List(selected_cells)
where table is the widget ID of a table widget in standard selection mode.
To reform the array returned by
WIDGET_CONTROL, table, GET_VALUE=Selection_Value
for a standard selection into one-dimensional array like those returned for disjoint selections, use the following command:
REFORM(Selection_Value, N_ELEMENTS(Selection_Value), 1)