01-20-2015 02:38 AM - edited 01-20-2015 02:39 AM
I have a 96-column table with strings. I also have 96-elemets int array (mask) with 1 and 0's.
What i want to do is to is to delete (or hide - but i've read that it's not possible) all the columns with index corresponding to 0 in mask array.
example:
table columns
1 2 3 4 5
mask
0 1 0 0 1
I want to delete columns 1, 3 and 4 and leave only 2 and 5 in my table.
How can i do that?
If i create for loop with i as index of the column, when i do DeleteTableColumns() columns count decreases, and i get an out-of range error:(
Or do i have a possibility to hide unneeded columns (not set their width to 1, it's very ugly-looking)?
Please help me(((
Solved! Go to Solution.
01-20-2015 03:00 AM
Hello rovnyart!
1. Removing table columns:
I suspect that the reason why you are getting the out-of-range error is due to the fact that in your for-loop, as you are deleting columns from the table, you'll eventually end up referencing a column that does no longer exist, because other columns before it have been deleted. While you are deleting each column at a time from your table in the for-loop, the column index number will shift, because you have deleted other columns before it.
In order to solve this, while you are deleting a column in your for-loop, make sure you also take into account that the column index is shifted because of removed columns.
2. Hiding table columns:
You can use the ATTR_COLUMN_VISIBLE attribute to hide table columns:
http://zone.ni.com/reference/en-XX/help/370051Y-01/cvi/uiref/cviattrcolumnvisible_column/
3. Alternatives:
Note that another alternative would also be to use a tree control instead, as the tree control also supports hidable columns:
http://forums.ni.com/t5/LabWindows-CVI/Table-Hide-Column/td-p/569773
Best regards!
- Johannes
01-20-2015 03:24 AM
1. Removing table columns:
I suspect that the reason why you are getting the out-of-range error is due to the fact that in your for-loop, as you are deleting columns from the table, you'll eventually end up referencing a column that does no longer exist, because other columns before it have been deleted. While you are deleting each column at a time from your table in the for-loop, the column index number will shift, because you have deleted other columns before it.
In order to solve this, while you are deleting a column in your for-loop, make sure you also take into account that the column index is shifted because of removed columns.
Or more simpler start deleting columns from the end of the table
01-20-2015 10:29 AM
2. Hiding table columns:
You can use the ATTR_COLUMN_VISIBLE attribute to hide table columns:
That's not supported for tables, only for trees:(
01-20-2015 10:39 AM
...this depends on the version of CVI. For trees this attribute is available since version 7, for tables since version 2012.
01-20-2015 10:43 AM
In order to solve this, while you are deleting a column in your for-loop, make sure you also take into account that the column index is shifted because of removed columns.
And how should i do that?=)
01-20-2015 11:08 AM
for example having a loop index and a separate column index
01-20-2015 02:21 PM
thanks a lot, my friends!
I've updated to CVI 2012 and found, that ATTR_COLUMN_VISIBLE works on tables) Problem solved
01-21-2015 04:09 AM
You are very welcome, rovnyart! You should also give credits to RobertoBozzolo, as his proposed solution for iterating over the control columns backwards is a lot simpler and straightforward, than the mechanism required to iterate over the columns from the beginning.
Best regards!
- Johannes