I have a C # Net 2.0 Windows Forms ListView with about ten columns filled with data when the application starts. The data is huge, so it cannot be reloaded quickly. My ListView has a Details View element and allows the user to resize each column separately.
The user can hide any of ten columns or several of them immediately and again display the columns at any time in a non-specific row. Data is not deleted when the column is hidden.
The following actions I tried but the result was not satisfied:
1) Resizing a column with a size of 0 will make it somewhat disappear until the user starts playing with columns. The user will accidentally resize them, because there is an option in my ListView that allows the user to manually resize each column.
2) When deleting a column, the following problem arises: when I try to add a column back, the column does not remember its position and size. Position is the main problem, I will try to explain why. If my user decides to hide “column 2” first and then “column 3” and then the user hides 3 to 2, then “Index 2” does not exist, so I cannot insert index No. 3, and the exception is raised. Even if I remember the position of the index before deleting, I cannot simply return the column back to this index, because I do not know if there were previous columns that were already hidden, or which column disappeared before or after, or whether or not were hidden. Thus, the scenario can be as follows: 1 shown, 2 hidden, 3 hidden, 4 shown, 5 hidden, 6 hidden, 7 hidden, 8 shown, 9 hidden, 10 hidden.
Possible solutions "1)" and "2)" are automatically excluded in the script. It is even better to make the column width equal to zero, but since my user will be able to resize the columns at any time as necessary, resizing to zero cannot be hidden from the user. The user will display it in size, and my system will assume that it is still hidden, etc. Etc., And it doesn’t look professional if the hidden columns can simply be “reversed” or as we might call it another.
Anyone have a better idea? Why is there no “visible” or “hidden” property in the ListView column, interesting? If someone has done this already before submitting the solution.
I must add that when adding data, I use automation of all the columns in my list. For this reason, the answer below does not work. The resize event cannot determine the width -1. All invisible columns with a width of 0 will be changed when the data is added. Since listview cuts out data that overlays the length of the column, I need to autoresist it forever. Explorer does not have this problem because it fits the columns to the length of the data. C # does not have such an extended list, here I have to set the columns to -1 every time I add data. The idea of column.width = 0 for hiding columns does not work in this concept.