 |
| Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET). |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 1st, 2004, 10:04 PM
|
|
Authorized User
|
|
Join Date: Jul 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hiding Listview Columns?
Hello,
Is it possible to hide a listview control column? I want to pass the value held in that column but not necessarily display it, e.g. I have one column called "employeeID" and another called "employeeRefNo". The former is used as a database table primary key behind the scenes and, therefore, doesn't need to be displayed. The latter is used by the application user in the "real world" and should be displayed.
I've looked online and it would appear that it can't be done :(
Thanks.
|
|

March 2nd, 2004, 08:55 AM
|
|
Authorized User
|
|
Join Date: Jul 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Done it - just set the column width property to 0. Simple!
|
|

March 2nd, 2004, 02:26 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
the ListItem object has a Tag property that can be used to store a custom string. This is more convenient if the user can resize the listView headers (and thus shows the 'hidden' column.)
Marco
|
|

March 2nd, 2004, 08:28 PM
|
|
Authorized User
|
|
Join Date: Jul 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
That's useful to know Marco, thanks. :)
|
|

March 2nd, 2004, 08:59 PM
|
|
Authorized User
|
|
Join Date: Jul 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Marco
I think the "Tag" property can only hold one value(?) Since I use the listview to display several different records, the "Tag" value is of limited use... I think.
Thanks
Jake
|
|

March 3rd, 2004, 03:43 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The Tag property of the ListItem is a String (luckily, it is an int in other components), thus it is possible to concatenate multiple values using a unique separator (like vbTab). That means the Tag property needs to be parsed to get its values (with Split).
Another solution (it is what I usually use) is to define a class that holds all the data for each row. When a row is added in the list (or whatever other component like a TreeView) a new class is created and filled with the data, the class is added to a collection with a unique key and the key is stored in the Tag.
Marco
|
|

June 4th, 2007, 05:43 AM
|
|
Registered User
|
|
Join Date: Jun 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
quote:Originally posted by jakeone
Hello,
Is it possible to hide a listview control column? I want to pass the value held in that column but not necessarily display it, e.g. I have one column called "employeeID" and another called "employeeRefNo". The former is used as a database table primary key behind the scenes and, therefore, doesn't need to be displayed. The latter is used by the application user in the "real world" and should be displayed.
I've looked online and it would appear that it can't be done :(
Thanks.
|
in desing time edit your listview to have, lets say 3 columns, and do this in your code to add a row
Code:
dim si as MSComctlLib.ListSubItem
with lstMyList.listitems
.add ,"k" & lngMyId,"mi first col"
with .item("k" & lngMyId).listsubitems
set si = .add(,"second col","mi second value")
si.tag = "mi optional tag on col2"
set si = .add(,"third col","mi third value")
si.tag = "mi optional tag on col3"
set si = .add(,"first hidden","mi hidden value")
si.tag = "my optional tag on the first hidden col"
end with
end with
that works to add a hiden column, just ensure to use the listview of the mscomctl.ocx not the comctl32.ocx
to make visible or hide a column its a lil harder code, but if u read the class' propertyes of the library its pretty intuitive.
if what u want its to hide a current visible column then u would have to reorder all the subitems in all your items, putting the subitem of the column to hide at the last, then just delete a header and thats all. i didnt try the last one, but im pretty sure it works.
|
|

June 4th, 2007, 05:53 AM
|
|
Registered User
|
|
Join Date: Jun 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
quote:Originally posted by darkshaped
Quote:
|
quote:Originally posted by jakeone
|
Quote:
Hello,
Is it possible to hide a listview control column? I want to pass the value held in that column but not necessarily display it, e.g. I have one column called "employeeID" and another called "employeeRefNo". The former is used as a database table primary key behind the scenes and, therefore, doesn't need to be displayed. The latter is used by the application user in the "real world" and should be displayed.
I've looked online and it would appear that it can't be done :(
Thanks.
|
in desing time edit your listview to have, lets say 3 columns, and do this in your code to add a row
Code:
dim si as MSComctlLib.ListSubItem
with lstMyList.listitems
.add ,"k" & lngMyId,"mi first col"
with .item("k" & lngMyId).listsubitems
set si = .add(,"second col","mi second value")
si.tag = "mi optional tag on col2"
set si = .add(,"third col","mi third value")
si.tag = "mi optional tag on col3"
set si = .add(,"first hidden","mi hidden value")
si.tag = "my optional tag on the first hidden col"
end with
end with
that works to add a hiden column, just ensure to use the listview of the mscomctl.ocx not the comctl32.ocx
to make visible or hide a column its a lil harder code, but if u read the class' propertyes of the library its pretty intuitive.
if what u want its to hide a current visible column then u would have to reorder all the subitems in all your items, putting the subitem of the column to hide at the last, then just delete a header and thats all. i didnt try the last one, but im pretty sure it works.
|
i forgot, if your list is of employee then you sould save the id in the item's tag property, if that table have references to other tables then the id of the fields you save it in the subitems's tag property of the correspondent item and subitem, like i didnt before, but i forget to show u how to save the row tag:
Code:
with lstMyList.listitems
.add ,"k" & lngMyId,"mi first col"
.item("k" & lngMyId).tag = lngMyId'the id of the row
with .item("k" & lngMyId).listsubitems
'the above code
end with
end with
i forgot cause i didnt find any utility to that, cause i save the row id in the key, and its even easyer to find it when u have to update the row, and the user will be always able to modify most of the field, but the id generally isnt a modifyable field.
|
|

June 4th, 2007, 06:18 AM
|
|
Registered User
|
|
Join Date: Jun 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
quote:Originally posted by marcostraf
The Tag property of the ListItem is a String (luckily, it is an int in other components), thus it is possible to concatenate multiple values using a unique separator (like vbTab). That means the Tag property needs to be parsed to get its values (with Split).
Another solution (it is what I usually use) is to define a class that holds all the data for each row. When a row is added in the list (or whatever other component like a TreeView) a new class is created and filled with the data, the class is added to a collection with a unique key and the key is stored in the Tag.
Marco
|
concatenate values in the tag, and parse? awfull solution, i wouldnt do that, what about if some field user is a detail, and have the split characters, the solution could end in a app crush
|
|

March 15th, 2008, 04:33 AM
|
|
Registered User
|
|
Join Date: Mar 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Dear All,
How much columns you have in Listview only same no of SubItems will be displayed in the listview. All extra subitems will be hidden.
Example:
--------
With lvwUserQuota
.Items.Add("Demo")
.Items(0)SubItems.Add("Demo sub item")
.Items(0)SubItems.Add("Demo sub hidden item-1")
.Items(0)SubItems.Add("Demo sub hidden item-2")
.Items(0)SubItems.Add("Demo sub hidden item-3")
End With
All "Demo sub hidden item-x" items will be hidden.
Note: listview has only two columns.
Best of luck
Fazee4u
|
|
 |