LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Can I build a table dynamically and set Column Titles?

I need to be able to programmatically build a table with a variable amount of rows and columns. The caller would provide a multi-dimensional array (along with the column string headings" and I need to take the values and build a table displaying the values. I was thinking about using InsertTableColumns and InsertTableRows to do this. Is it possible to also set the Column Titles and if so how would I do that? I don't see a parameter in the InsertTableColumns call to add the title. Also, in the .uir file would I start with just a one column one row table and then add on from there? Does anyone have sample code which does this?
Thanks,
Donna
0 Kudos
Message 1 of 5
(3,893 Views)
Here are quick responses to your questions.

You can use the "SetTableColumnAttribute" function with the "ATTR_LABEL_TEXT" with the attribute to set the column names. Similarly, the "SetTableRowAttribute" function can be used to set the row names.

The table in the user interface can have zero rows and zero columns. Rows and columns can be added programatically using the "InsertTableRows" and "InsertTableColumns" functions, respectively.

I hope this helps.

Randy
Message 2 of 5
(3,893 Views)
Just one addendum to what Randy wrote.

In addition to ATTR_LABEL_TEXT, you will also need to set the ATTR_USE_LABEL_TEXT row & column attribute to 1. This is what tells the table to use the text you set with ATTR_LABEL_TEXT, instead of using the default numbers.

Luis
NI
Message 3 of 5
(3,872 Views)
Luis,

I want to set a different label for each column of a table that I built programatically. I have the following code but it only sets all of the columns to the same value. Do you know how I can set each column to a different value. I have included a portion of my code which adds columns and supposedly sets the column header. Can you tell me why each column is not being set to it's own specific value? I have used the debugger and the_col_des contains a different value each time through the loop, yet all columns end up with the last value.
thanks,
Donna
for (int cix = 0; cix < num_cols; cix++)
{
Info& colinfo = the_table[cix][0] ;
string col_des = colinfo.getShortTitle();
const char* the_col_des = col_des.c_str();
error = SetTableColumnAttribute (table_panel, TABLE_P_NORMAL_TABLE, -1, ATTR_USE_LABEL_TEXT, 1);
error = SetTableColumnAttribute (table_panel, TABLE_P_NORMAL_TABLE, -1, ATTR_LABEL_TEXT, the_col_des);
error = InsertTableColumns (table_panel, TABLE_P_NORMAL_TABLE, 1, 1, VAL_CELL_STRING);
}
}
}
0 Kudos
Message 4 of 5
(3,802 Views)
In the for loop you have passed -1 as the "Column index" parameter to SetTableColumnAttribute: this way, at each iteration you are setting the attribute to ALL column (thas why at the end all columns report the same -last- title).

To set individual columns, pass (cix + 1) instead (remember that columns are 1-base indexed).


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 5 of 5
(3,796 Views)