Vba ListView add items

  1. Member
    I am having trouble adding items to individual columns. When I do the following:

    Listview1.Columns[0].ListView.Items.Add["Hello"]
    Listview1.Columns[1].ListView.Items.Add["Goodbye"]

    Everything gets added to the first column instead of the assigned column.

  2. 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"
  3. Member

    Re: Add items to listview columns

    MSComctlLib.ListItem does not appear to be an acceptabe variable type in VB
  4. Re: Add items to listview columns

    I don't have vb6 here... and I am doing this from memory...
    1. Dim objListItem As ListItem

    2. Set objListItem = Me.ListView1.ListItems.Add["AAA"]

    3. objListItem.SubItems[1] = "BBB"

    4. 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
  5. Member

    Re: Add items to listview columns

    I am using VB 2008 but that does not seem to be an option in 2008
  6. 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
  7. 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:

    //msdn.microsoft.com/en-us/libr....listview.aspx

    Have a look there, and then post back with any specific questions.

    Hope that helps!!

    Gary

  8. 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:

    For i = 0 To [Numteams - 1]

    For j = 0 To [Numteams - 1]

    If ranking[j] = [i + 1] Then

    Results.TmNumber.Items.Add[Teamnumber[j]]
    Results.Tmname.Items.Add["" & Teamname[j]]
    Results.TmResult.Items.Add[teamtotal[j]]
    Results.Tmprcnt.Items.Add["" & teamprcnt[j].ToString["0.00"] & "%"]

    If istied[j] = False Then
    Results.Tmrank.Items.Add[ranking[j]]
    Else
    Results.Tmrank.Items.Add["" & ranking[j] & "="]
    End If

    End If

    Next

    Next

    I have tried to replace it with:

    Dim LVI as new listviewitem [note the other variables have already been assigned]

    For i = 0 To [Numteams - 1]

    For j = 0 To [Numteams - 1]

    LVI.SubItems.Clear[]

    If ranking[j] = [i + 1] Then

    If istied[j] = True Then
    LVI.SubItems.Add["" & ranking[j] & "="]
    Else
    LVI.SubItems.Add[ranking[j]]
    End If

    LVI.SubItems.Add[Teamnumber[j]]
    LVI.SubItems.Add[Teamname[j]]
    LVI.SubItems.Add[teamtotal[j]]
    LVI.SubItems.Add[teamprcnt[j]]
    Results.ListView1.Items.Insert[i, LVI]

    End If
    Next
    Next

  9. Re: Add items to listview columns

    Hey,

    I think in this situation a screen shot would greatly help in order to understand the problem.

    Gary

  10. Member

    Re: Add items to listview columns

    Sorry, I don't quite know what you mean in "screen shot".
  11. Re: Add items to listview columns

    Hey,

    You say you have a working sample where the items are split over multiple ListBoxes, yes?

    In which case a screen shot of the application as it stands will help us understand what your requirement is.

    Have a look here:

    //www.wikihow.com/Take-a-Screen...rosoft-Windows

    If you are not sure.

    Gary

  12. Member

    Re: Add items to listview columns

    See attached.

    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
  13. 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.
  14. 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.

  15. 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 :

    NewEntry = lvwGroups.Items.Add[SHG.Title] NewEntry.SubItems.Add[SHG.Description] NewEntry.SubItems.Add[SHG.Power.ToString] NewEntry.SubItems.Add[SHG.Interest.ToString]
    As that is the bit which actually creates the record which spans several columns.
  16. Member

    Re: Add items to listview columns

    Thanks. That is now working "tickety boo".
  17. New Member

    Re: Add items to listview columns

    Originally Posted by keystone_paul
    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 :

    NewEntry = lvwGroups.Items.Add[SHG.Title] NewEntry.SubItems.Add[SHG.Description] NewEntry.SubItems.Add[SHG.Power.ToString] NewEntry.SubItems.Add[SHG.Interest.ToString]
    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..
  18. Registered User

    Re: Add items to listview columns

    Can I have all
    the source code please ?
  19. 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Forum Rules

Click Here to Expand Forum to Full Width

Video liên quan

Chủ Đề