From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Trouble with Tables...

CVI 2012

 

I'm learining how to programmatically generate a table that is partly numerics and partly buttons.  If have found that this does ot work:

 for (row=1;row<NUM_NET_TABLE_ROWS+1;row++)
 
  for (col=1;col<NUM_NET_NUMERIC_COLUMNS+1;col++)
   {
    err = SetTableCellAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakePoint(col,row), ATTR_MIN_VALUE, 0.0);
   err = SetTableCellAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakePoint(col,row), ATTR_MAX_VALUE, 150.0);
   err = SetTableCellAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakePoint(col,row), ATTR_NUM_CELL_DFLT_VALUE, 1.0);
    }

And also, this does not work:

 SetTableCellRangeAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakeRect (1, 1, NUM_NET_TABLE_ROWS, NUM_NET_NUMERIC_COLUMNS),  ATTR_MIN_VALUE, 0.0);
  SetTableCellRangeAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakeRect (1, 1, NUM_NET_TABLE_ROWS, NUM_NET_NUMERIC_COLUMNS), ATTR_MAX_VALUE, 136.0);
 SetTableCellRangeAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakeRect (1, 1, NUM_NET_TABLE_ROWS, NUM_NET_NUMERIC_COLUMNS), ATTR_NUM_CELL_DFLT_VALUE, 117.3);

 

None of these generate errors, they do nothing.  The numeric cells do not take on these attributes.  I also set these cells to COERCE, but there is no way to tell if that works or not.

 

And the SetTableColumnAttribute function panel says it cannot change cell attributes.

 

So how does one set these attributes on table cells as they are built?

0 Kudos
Message 1 of 10
(4,086 Views)

Just a few ideas about tables: I don´t know if thy apply to your situation or not.

 

SetTableCellAttributeworks on existing cells: you must create rows and column first.

Second, a table cell can actually hold all admittible cell types and values, but it actually displays one type only. That is, you can store in a cell both a string and a number: the type displayed is determined by ATTR_CELL_TYPE attribute. This can be the reason why you do not get an error when setting an attribute but you do not see its effect: the default cell type is string so you do not see numeric attributes unless you change the cell data type.

 

Finally, you can use VAL_TABLE_COLUMN_RANGE (column), VAL_TABLE_ROW_RANGE (row) and VA_TABLE_ENTIRE_RANGE macros which simplify addressing the more common ranges in a table.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 10
(4,081 Views)

Thank you Roberto, for the reply.  What I have done is place a table control on a panel, then programmatically create rows and columns, add row and column labels.  I am setting the cells to numeric, and later to Float.  What I see is a bunch of numeric cells, that are HOT.  I can select one, use INC/DEC and change the values.  I just cant set MIN or MAX or DEFAULT values. 

 

Perhaps I have things out of order.  Here is the whole  block of code.  Below, you will see a image of a portion of the table, showing column headers, float cells, and a selected cell with a negative number in it.  If the MIN attribute was accepted, it should not have allowed me to do that.

 

 // -------------------------------------------------------------------------------------------------------------------------------
 // Construct the UPS Table
 // -------------------------------------------------------------------------------------------------------------------------------
 InsertTableRows (upsStatusTabHandle,   TAB_UPSSTS_UPS_TABLE, 1, NUM_NET_TABLE_ROWS,      VAL_CELL_NUMERIC);
 InsertTableColumns (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, 1, NUM_NET_NUMERIC_COLUMNS,     VAL_CELL_NUMERIC);     

 // Set up the Rows
 err = SetTableRowAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, -1, ATTR_USE_LABEL_TEXT,   TRUE);
 err = SetTableRowAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, -1, ATTR_LABEL_BOLD,    TRUE);
 err = SetTableRowAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, -1, ATTR_LABEL_JUSTIFY,   VAL_CENTER_LEFT_JUSTIFIED);
 err = SetTableRowAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, -1, ATTR_LABEL_POINT_SIZE,  20);
  err = SetTableRowAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, -1, ATTR_SIZE_MODE,     VAL_USE_EXPLICIT_SIZE);
  err = SetTableRowAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, -1, ATTR_ROW_HEIGHT,    36);

 for (row=1;row<NUM_NET_TABLE_ROWS+1;row++)
  err = SetTableRowAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, row, ATTR_LABEL_TEXT,   NetNodeTableRow[row-1].Label);
  
 SetCtrlAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, ATTR_ROW_LABELS_WIDTH,       250);
 SetCtrlAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, ATTR_HIDE_HILITE,        TRUE);
 
 
 SetTableCellRangeAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakeRect (1, 1, NUM_NET_TABLE_ROWS, NUM_NET_NUMERIC_COLUMNS),
           ATTR_CHECK_RANGE, VAL_COERCE);
 
 // Modify individual cells
 for (row=1;row<NUM_NET_TABLE_ROWS+1;row++)
  for (col=1;col<NUM_NET_NUMERIC_COLUMNS+1;col++)
   {
   err = SetTableCellAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakePoint(col,row), ATTR_TEXT_BOLD,    TRUE);
   err = SetTableCellAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakePoint(col,row), ATTR_PRECISION,    1);
   err = SetTableCellAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakePoint(col,row), ATTR_DATA_TYPE,    VAL_FLOAT);
    err = SetTableCellAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakePoint(col,row), ATTR_CELL_JUSTIFY,    VAL_CENTER_RIGHT_JUSTIFIED);
   err = SetTableCellAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakePoint(col,row), ATTR_TEXT_POINT_SIZE,  20);
   err = SetTableCellAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakePoint(col,row), ATTR_MIN_VALUE, 0.0);
   err = SetTableCellAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakePoint(col,row), ATTR_MAX_VALUE, 150.0);
   err = SetTableCellAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakePoint(col,row), ATTR_NUM_CELL_DFLT_VALUE, 1.0);
   }
  
 // Modify ranges of cells
 SetTableCellRangeAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakeRect (1, 1, NUM_NET_TABLE_ROWS, NUM_NET_NUMERIC_COLUMNS),
           ATTR_SHOW_INCDEC_ARROWS, 1);
 SetTableCellRangeAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakeRect (1, 1, NUM_NET_TABLE_ROWS, NUM_NET_NUMERIC_COLUMNS),
           ATTR_MIN_VALUE, 0.0);
  SetTableCellRangeAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakeRect (1, 1, NUM_NET_TABLE_ROWS, NUM_NET_NUMERIC_COLUMNS),
           ATTR_MAX_VALUE, 136.0);
 SetTableCellRangeAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakeRect (1, 1, NUM_NET_TABLE_ROWS, NUM_NET_NUMERIC_COLUMNS),
           ATTR_NUM_CELL_DFLT_VALUE, 117.3);
   SetTableCellRangeAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakeRect (1, 2, NUM_NET_TABLE_ROWS, 1),
           ATTR_MAX_VALUE, 136.0);
 SetTableCellRangeAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakeRect (1, 2, NUM_NET_TABLE_ROWS, 1),
           ATTR_NUM_CELL_DFLT_VALUE, 122.6);
   SetTableCellRangeAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakeRect (1, 3, NUM_NET_TABLE_ROWS, 1),
           ATTR_MAX_VALUE, 3000.0);
  SetTableCellRangeAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakeRect (1, 3, NUM_NET_TABLE_ROWS, 1),
           ATTR_NUM_CELL_DFLT_VALUE, 734.3);
 SetTableCellRangeAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakeRect (1, 4, NUM_NET_TABLE_ROWS, 1),
           ATTR_MAX_VALUE, 30.0);
 SetTableCellRangeAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakeRect (1, 4, NUM_NET_TABLE_ROWS, 1),
           ATTR_NUM_CELL_DFLT_VALUE, 27.1);
  SetTableCellRangeAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakeRect (1, 5, NUM_NET_TABLE_ROWS, 1),
           ATTR_MAX_VALUE, 100.0);
 SetTableCellRangeAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakeRect (1, 5, NUM_NET_TABLE_ROWS, 1),
           ATTR_NUM_CELL_DFLT_VALUE, 98.3);
  SetTableCellRangeAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakeRect (1, 6, NUM_NET_TABLE_ROWS, 1),
           ATTR_MAX_VALUE, 130.0);
 SetTableCellRangeAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakeRect (1, 6, NUM_NET_TABLE_ROWS, 1),
           ATTR_NUM_CELL_DFLT_VALUE, 89.9);
  SetTableCellRangeAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakeRect (1, 7, NUM_NET_TABLE_ROWS, 1),
           ATTR_MAX_VALUE, 99.0);
 SetTableCellRangeAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakeRect (1, 7, NUM_NET_TABLE_ROWS, 1),
           ATTR_NUM_CELL_DFLT_VALUE, 11.3);
  SetTableCellRangeAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakeRect (1, 8, NUM_NET_TABLE_ROWS, 1),
           ATTR_MAX_VALUE, 2500.0);
 SetTableCellRangeAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakeRect (1, 8, NUM_NET_TABLE_ROWS, 1),
           ATTR_NUM_CELL_DFLT_VALUE, 218.8);

 
 InsertTableColumns (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, NUM_NET_NUMERIC_COLUMNS+1, NUM_NET_TABLE_COLUMNS,    VAL_CELL_BUTTON);

 // Set up the column headers
 err = SetTableColumnAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, -1, ATTR_USE_LABEL_TEXT,   TRUE);
 err = SetTableColumnAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, -1, ATTR_LABEL_BOLD,    TRUE);
 err = SetTableColumnAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, -1, ATTR_LABEL_JUSTIFY,    VAL_CENTER_CENTER_JUSTIFIED);
 err = SetTableColumnAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, -1, ATTR_LABEL_POINT_SIZE,  14);
 err = SetTableColumnAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, -1, ATTR_COLUMN_WIDTH,   80);
 err = SetTableColumnAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, -1, ATTR_LABEL_WRAP_MODE, VAL_WORD_WRAP);
 
 // Insert header strings
 for (col=1;col<NUM_NET_TABLE_COLUMNS+1;col++)
  err = SetTableColumnAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, col, ATTR_LABEL_TEXT, NetNodeTableColumn[col-1].Label);
  
 // These must be last
 SetCtrlAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, ATTR_NUM_VISIBLE_COLUMNS,   NUM_NET_TABLE_COLUMNS);
 SetCtrlAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, ATTR_NUM_VISIBLE_ROWS,    NUM_NET_TABLE_ROWS);
 // -------------------------------------------------------------------------------------------------------------------------------

 

TableTrouble.jpg

0 Kudos
Message 3 of 10
(4,071 Views)

Whenever changing the data type of a cell, all of the numeric cell type attributes are reset. This includes the attribute ATTR_CHECK_RANGE. If you need to change the attribute ATTR_DATA_TYPE, make sure to change it first, or to go back and reset all of the numeric attributes.

 

This is occurring in the nested for loop with comment "Modify individual cells". I would recommend just calling SetTableCellRangeAttribute for all of the attributes in the for loops instead:

 

SetTableCellRangeAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakeRect (1, 1, NUM_NET_TABLE_ROWS, NUM_NET_NUMERIC_COLUMNS), ATTR_DATA_TYPE, VAL_FLOAT);

 

 

National Instruments
0 Kudos
Message 4 of 10
(4,057 Views)

D Biel, thank you.  I made the suggested changes, deleting the loops, and it works fine.

 

The default value attribute does not appear to work:

 SetTableCellRangeAttribute (upsStatusTabHandle, TAB_UPSSTS_UPS_TABLE, MakeRect (1, 1, NUM_NET_TABLE_ROWS, NUM_NET_NUMERIC_COLUMNS), ATTR_NUM_CELL_DFLT_VALUE, 17.3);

 

This was the last call in the sequence of calls to apply attributes to the numeric cells.  This is not a show stopper, just something to note.

Message 5 of 10
(4,048 Views)

I can confirm this.  It appears to be a bug.

 

// 1		SetTableColumnAttribute(sequenceTab,TABTESTS_TABLE,TEST_COL_NUM_VTOL,ATTR_MIN_VALUE,10);
// 2				SetTableCellRangeAttribute(sequenceTab,TABTESTS_TABLE,VAL_TABLE_COLUMN_RANGE(TEST_COL_NUM_VTOL),ATTR_NUM_CELL_DFLT_VALUE,30;
// 3		SetTableColumnAttribute(sequenceTab,TABTESTS_TABLE,TEST_COL_NUM_VTOL,ATTR_MAX_VALUE,99);
// 4		SetTableColumnAttribute(sequenceTab,TABTESTS_TABLE,TEST_COL_NUM_VTOL,ATTR_CHECK_RANGE,VAL_COERCE);

 

Lines #1, 3, and 4 in my example do work.  This column is coerced between 10 and 99.  But the default value just goes to 0 instead of 30 when new rows are added.  And I have my table set to column mode.

0 Kudos
Message 6 of 10
(3,779 Views)

Hello ElectroLund,

 

While I agree this behavior is not desirable, I wouldn't call it a bug.

In the help for ATTR_NUM_CELL_DFLT_VALUE it says:

This is the value to which the cell is set when the panel is loaded or when you call DefaultCtrl or DefaultPanel.

Obviously, inserting a row doesn't fall into these cases.

If you set ATTR_NUM_CELL_DFLT_VALUE using SetTableColumnAttribute(not SetTableCellRangeAttribute) and then insert a row and querry the value of ATTR_NUM_CELL_DFLT_VALUE you can see that you get the value you have set.

SetTableColumnAttribute (panel, PANEL_TABLE, 1, ATTR_NUM_CELL_DFLT_VALUE, 30);
InsertTableRows (panel, PANEL_TABLE, -1, 1, VAL_USE_MASTER_CELL_TYPE);
GetTableCellAttribute (panel, PANEL_TABLE, MakePoint (1, 3), ATTR_NUM_CELL_DFLT_VALUE, &def);

 

Constantin

 

0 Kudos
Message 7 of 10
(3,757 Views)

Ah, ok.  It's unfortunate that it doesn't work the way my mind wants it to work!  Smiley Very Happy

0 Kudos
Message 8 of 10
(3,746 Views)

I wonder why you use SetTableColumnAttribute for rows #1, #3 and #4 (which by the way are the ones that work) and SetTableCellRangeAttribute in line #2. The latter should operate on existing cells in the table, while the others affect the column itself and so are inherited on new lines (provided yourtable is set in column mode -which it is- and you use VAL_USE_MASTER_CELL_TYPE as the cell type, which probably you are already doing).

If there is no specific reason to use a different command, can you try using SetTableColumnAttribute for line #2 and see what happens?



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 9 of 10
(3,740 Views)

Roberto, good catch.  When I pasted that code, I had already tried the second method (SetTableCellRangeAttribute).  I had started with

SetTableColumnAttribute, which didn't work for me.  And you are right, I an inserting rows with the VAL_USE_MASTER_CELL_TYPE.

 

Strange and counterintuitive.

 

0 Kudos
Message 10 of 10
(3,734 Views)