Everything gets added to the first column instead of the assigned column.
Re: Add items to listview columns
'Declare ListItem
Dim LI As MSComctlLib.ListItem
'Clears ListView
ListView1.ListItems.Clear
'Add data to 3 pre-existing columns ( 0, 1 and 2)
Set LI = ListView1.ListItems.Add(, , "SomeData 0")
LI.SubItems(1) = "Data 1"
LI.SubItems(2) = "Data 2"
Member
Re: Add items to listview columns
MSComctlLib.ListItem does not appear to be an acceptabe variable type in VB
Re: Add items to listview columns
I don't have vb6 here... and I am doing this from memory...
Dim objListItem As ListItem
Set objListItem = Me.ListView1.ListItems.Add("AAA")
objListItem.SubItems(1) = "BBB"
objListItem.SubItems(2) = "CCC"
A good exercise for the Heart is to bend down and help another up... Please Mark your Thread "
Resolved", if the query is solved Microsoft MVP: 2011 - 2015 IMP Links : Acceptable Use Policy, FAQ MyGear: OMEN by HP - 15-ce073tx with Win10+Office 2013. || Mac Book Pro (10.6.8) with Office 2011
Member
Re: Add items to listview columns
I am using VB 2008 but that does not seem to be an option in 2008
I'm about to be a PowerPoster!
Re: Add items to listview columns
Originally Posted by boutells
I am using VB 2008 but that does not seem to be an option in 2008
Then you are not using Classic VB - Moved To VB.NET
Re: Add items to listview columns
Hey,
What exactly is it that you are trying to do?
Have you had a look at the documentation for the ListView:
Have a look there, and then post back with any specific questions.
Hope that helps!!
Gary
Member
Re: Add items to listview columns
I am trying to create a duplicate bridge scorer and at present I get the results the way I want them using 5 listboxes delineating the team rank, the team number, the team name, the team points and the team percent in the various listboxes.
The problem with this is if the number of entries is greater than the height of the listbox, then the user has to scroll down. Once the user has to scroll, the output in the various listboxes is not in sync.
I am trying to get around this by transferring the data into a listview box with each column taking the output previously assigned to a separate listbox. If I can do this, then when the user scrolls down, the rows will remain in sync.
The code I am using for the listboxes is as follows:
I have deliberately made the list boxes smaller in height than they need to be as i am working on a prototype that takes only 6 teams. When it is more advanced, it could take a much larger number so that the number could exceed the listbox height.
Each of the listboxes would have to scroll in sync to deliver the required output
Attached Images
Re: Add items to listview columns
Here's a quick example from a project i'm working on - I have a listview called lvwGroups with four columns and the view property is set to "detail".
The code below loops through a collection of items which contain the data and creates a new entry for each one, setting the data for each of the four columns :
Dim NewEntry As ListViewItem
Dim nX As Integer
lvwGroups.Items.Clear()
For Each SHG As clsStakeHolderGroup In _StakeHolderManagement.StakeHolderGroups
nX += 1
NewEntry = lvwGroups.Items.Add(SHG.Title)
NewEntry.SubItems.Add(SHG.Description)
NewEntry.SubItems.Add(SHG.Power.ToString)
NewEntry.SubItems.Add(SHG.Interest.ToString)
NewEntry.Tag = nX
Next
Your initial example code was adding trying to add listitems to columns - I've never seen that attempted before - maybe it works, maybe it doesn't, but the way I've always done it is to add subitems to a listviewitem.
Member
Re: Add items to listview columns
Your loop language is a bit more sophisticated that that which I have used up to now but I tweaked it a little and think I am making progress in a basic experimental item.
I will now try it in the project proper and see if it works.
Thanks for your help; I may come back on this a little later.
Re: Add items to listview columns
No problem - like I say I've just lifted code that I'm working on.
You can use any method you like to get the sets of data to add, the important lines are :
As that is the bit which actually creates the record which spans several columns.
im trying to make a application that looks like this, can anyone tell me how to add for example the text in textbox name to column in listview name, textboxt with text of surname to add to the column surname and so on... this action will be done by pressing a btn add student..
Registered User
Re: Add items to listview columns
Can I have all the source code please ?
Registered User
Re: [RESOLVED] Add items to listview columns
I am just a beginner here. and I want to know how to add and remove listview item in visualbasic . . need your help