LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to delete table columns on 1-0 mask?

Solved!
Go to solution

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(((

 

0 Kudos
Message 1 of 9
(5,016 Views)
Solution
Accepted by topic author rovnyart

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://forums.ni.com/t5/LabWindows-CVI-Idea-Exchange/Add-ATTR-COLUMN-VISIBLE-attribute-for-table-col...

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

0 Kudos
Message 2 of 9
(5,010 Views)

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 Smiley Wink



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

 

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:(

0 Kudos
Message 4 of 9
(4,990 Views)

...this depends on the version of CVI. For trees this attribute is available since version 7, for tables since version 2012.

0 Kudos
Message 5 of 9
(4,987 Views)

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?=)

0 Kudos
Message 6 of 9
(4,985 Views)

for example having a loop index and a separate column index

0 Kudos
Message 7 of 9
(4,978 Views)

thanks a lot, my friends!

I've updated to CVI 2012 and found, that ATTR_COLUMN_VISIBLE works on tables) Problem solved

0 Kudos
Message 8 of 9
(4,974 Views)

You are very welcome, rovnyart! You should also give credits to 

 

0 Kudos
Message 9 of 9
(4,958 Views)