Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Programming ListView

Posted on 2001-07-24
14
241 Views
Last Modified: 2010-05-02
I have a listview I want to display the following information(ID FirstName LastName SSS). I want each row to show(FirstName LastName SSS) and each the ID of each row to be hidden and diplayed when someone double clicks that row. For example if I have a combobox called combo1 I can do this. combo1.AddItem("John") combo1.itemData(2) I want something similar with a listview control.

I want also to correctly size the listView and avoid horizontal scrolls.


here is my code

w = ListView1.Width / 4

listView1.ColumnHeaders.Add , , "First name", w
listView1.ColumnHeaders.Add , , "Last name", w
listView1.ColumnHeaders.Add , , "DOB", w
listView1.ColumnHeaders.Add , , "SSN", (ListView1.Width - 3*w)

But that is shows the horizontal scroll bar.

Thank you
0
Comment
Question by:jc64
  • 5
  • 4
  • 2
  • +3
14 Comments
 
LVL 28

Expert Comment

by:Ark
ID: 6315662
Use .tag property of listitem
Dim itm As ListItem
Set itm = ListView1.Add( , ,"John")
itm.Tag = 2

Cheers
0
 
LVL 28

Accepted Solution

by:
Ark earned 200 total points
ID: 6315669
Or, if ID is unique, use .Key property:

ListView1.Add ,"key" &CStr(ID) ,"John")

After this you can access ListItem by key:
ID = 100
ListView1.Listitems("key" & ID).Selected = True

or
Private Sub ListView1_ItemClick(ByVal Item As ComctlLib.ListItem)
   Debug.Print Item.Key
' or Debug.Print Item.Tag
End Sub
0
 

Author Comment

by:jc64
ID: 6315793
Ark, in the frist comment, how can I access the tag value.

For instance when someone clicks

msgBox listview.something

to display the tag value

Thanks
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 28

Expert Comment

by:Ark
ID: 6315800
msgbox ListView.SelectedItem.Tag

Cheers
0
 
LVL 28

Expert Comment

by:Ark
ID: 6315803
Or
ListView1.ListItems(5).Tag
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 6315823
The problem with the horizontal scroll bar appearing seems to be because the widht that you are using for the columns IS NOT what is actually being used.  I tried the following experiment:

Using your code exactly as shown, with a ListView which had a width of 3180 (w=795).

After setting the columnheaders as in the code, the scroll bar appears, and in the Immediate window, I displayed the value of the ListView1.ColumnHeaders(1).Width  to get a value, as set in the control of: 794.8347

I then played around with the width value w, setting it to specific values, and assigning the same value to all 4 columns, to find what value was required in order to NOT get a Horizontal Scroll Bar:

The Maximum value of w that did not create a Scroll Bar was
787.4646!!!   Go Figure.



0
 
LVL 1

Expert Comment

by:superchook
ID: 6315910
I think it's related to the borders between columns, and possibly an allowance for different fons / char spacing.
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 6316828
It would appear that if you allow approximately 1% of the ListView Width for these "related items", then the column width that you assign will come out about right.  thus you would have :

REMEBER that the Width paroperty of a column is a type SINGLE value (not INTEGER):

Dim w as Single

w = 0.99 * ListView1.Width/4

0
 

Expert Comment

by:GrahamAtJobserve
ID: 6317376
Remember to allow for the width of the vertical scroll bar when setting the column widths, or your list view will suddenly get a horizontal scroll when the list fills sufficiently to need a vertical scroll bar.

Columns widths are a pain though cos you cant see them at design time.

Graham.
0
 

Author Comment

by:jc64
ID: 6317879
Thank you all and I am Ok with Ark's answer for the tag potion of the quation. I am considering the Horizaontal scroll problem now and will make a decistion today.

Thanks
0
 

Expert Comment

by:johnread
ID: 6318335
Remember you can set the width of a column to zero.
0
 

Author Comment

by:jc64
ID: 6320445
I want to accept the answers of ARK and Arthur_Wood and will split the 200 ponts between them. I am going to reduce the points to 100 and will accept ARK's comment. then I will create another one with the name "List View For Arther_wood". Arthur_Wood, please add some comment to that question and I will award you the points.


Thanks All, I appreciate.
0
 

Author Comment

by:jc64
ID: 6320448
Sorry the system will not allow me the reduce the points. Anyone with a suggestion on how I can share the points to Ark and Arhter_wood.

Thanks
0
 

Author Comment

by:jc64
ID: 6320469
Sorry the system will not allow me the reduce the points. Anyone with a suggestion on how I can share the points to Ark and Arhter_wood.

Thanks
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Problem to skip loop 6 62
How to compare ms sql hashbytes results within vb6 5 84
RUNRMTCMD from AS/400 12 68
Copy a range from 1..n excel sheets to one destination sheet 2 55
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question