Results 1 to 8 of 8
  1. #1
    nathanael890's Avatar
    Join Date
    Aug 2008
    Gender
    male
    Posts
    158
    Reputation
    13
    Thanks
    46
    My Mood
    Bored

    [Help]adding items to the listview code


    guys. I need some help here.

    if I want to add something to the listbox by this code
    Code:
        Public Sub Add_Item( _
        ByVal Moderator As String, _
        ByVal User As String, _
        ByVal Type As String, _
        ByVal Points As String, _
        ByVal Reason As String)
            Dim Count As Integer = 0
            ListView1.Items.Add(Moderator)
            ListView1.Items(Count).SubItems.Add(User)
            ListView1.Items(Count).SubItems.Add(Type)
            ListView1.Items(Count).SubItems.Add(Points)
            ListView1.Items(Count).SubItems.Add(Reason)
            Count += 1
        End Sub
    it just appears as 1 and it can't add other items no longer..
    could someone solve this problem... thanks.

  2. #2
    confict's Avatar
    Join Date
    Aug 2010
    Gender
    male
    Posts
    422
    Reputation
    3
    Thanks
    290
    My Mood
    Relaxed
    Where's the count function for ?
    Why you dont just use
    listview.items.add("") ?

    ITS MEH BITCHESSS !!!

  3. #3
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by confict View Post
    Where's the count function for ?
    Why you dont just use
    listview.items.add("") ?
    There is no count "function" there, and this sub is to simplify work obviously.

    @OP
    Okay first off, your logic is all wrong for the count variable.
    [php]
    Dim Count As Integer = 0
    ListView1.Items.Add(Moderator)
    ListView1.Items(Count).SubItems.Add(User)
    ListView1.Items(Count).SubItems.Add(Type)
    ListView1.Items(Count).SubItems.Add(Points)
    ListView1.Items(Count).SubItems.Add(Reason)
    Count += 1
    [/php]

    Let's see...every time you call the sub you're declaring an integer with a value of 0, so it's going be 0 all the time...

    Instead try:

    [php]
    Public Sub Add_Item( _
    ByVal Moderator As String, _
    ByVal User As String, _
    ByVal Type As String, _
    ByVal Points As String, _
    ByVal Reason As String)
    Dim Count As Int32 = Me.ListView1.Items.Count-1
    ListView1.Items.Add(Moderator)
    ListView1.Items(Count).SubItems.Add(User)
    ListView1.Items(Count).SubItems.Add(Type)
    ListView1.Items(Count).SubItems.Add(Points)
    ListView1.Items(Count).SubItems.Add(Reason)
    End Sub
    [/php]

    That should work.

    EDIT: For the sake of a better explanation + I'm bored:

    By changing count to "Me.ListBiew1.Items.Count-1" you've assigned the variable "count" to a dynamic value that will change as more items are added, rather than a static "0" which will never change which resulted in you finding it kept overwriting previous entries right?
    Last edited by Jason; 10-02-2010 at 09:35 AM.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  4. The Following 2 Users Say Thank You to Jason For This Useful Post:

    confict (10-02-2010),nathanael890 (10-03-2010)

  5. #4
    confict's Avatar
    Join Date
    Aug 2010
    Gender
    male
    Posts
    422
    Reputation
    3
    Thanks
    290
    My Mood
    Relaxed
    Quote Originally Posted by Jason View Post


    There is no count "function" there, and this sub is to simplify work obviously.

    @OP
    Okay first off, your logic is all wrong for the count variable.
    [php]
    Dim Count As Integer = 0
    ListView1.Items.Add(Moderator)
    ListView1.Items(Count).SubItems.Add(User)
    ListView1.Items(Count).SubItems.Add(Type)
    ListView1.Items(Count).SubItems.Add(Points)
    ListView1.Items(Count).SubItems.Add(Reason)
    Count += 1
    [/php]

    Let's see...every time you call the sub you're declaring an integer with a value of 0, so it's going be 0 all the time...

    Instead try:

    [php]
    Public Sub Add_Item( _
    ByVal Moderator As String, _
    ByVal User As String, _
    ByVal Type As String, _
    ByVal Points As String, _
    ByVal Reason As String)
    Dim Count As Int32 = Me.ListView1.Items.Count-1
    ListView1.Items.Add(Moderator)
    ListView1.Items(Count).SubItems.Add(User)
    ListView1.Items(Count).SubItems.Add(Type)
    ListView1.Items(Count).SubItems.Add(Points)
    ListView1.Items(Count).SubItems.Add(Reason)
    End Sub
    [/php]

    That should work.

    EDIT: For the sake of a better explanation + I'm bored:

    By changing count to "Me.ListBiew1.Items.Count-1" you've assigned the variable "count" to a dynamic value that will change as more items are added, rather than a static "0" which will never change which resulted in you finding it kept overwriting previous entries right?
    Thanks for the explanation
    I never worked with listview so I just gave it a try ^^

    ITS MEH BITCHESSS !!!

  6. #5
    Blubb1337's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Germany
    Posts
    5,915
    Reputation
    161
    Thanks
    3,108
    [php] Dim Count As Int = 0
    ListView1.Items.Add(Moderator)
    Count = ListView1.Items.Count-1
    ListView1.Items(Count).SubItems.Add(User)
    ListView1.Items(Count).SubItems.Add(Type)
    ListView1.Items(Count).SubItems.Add(Points)
    ListView1.Items(Count).SubItems.Add(Reason) [/php]

    Else, the first count will be -1.



  7. #6
    'Bruno's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Portugal
    Posts
    2,883
    Reputation
    290
    Thanks
    1,036
    My Mood
    Busy
    Just create the item variable, add subitems to it.. and then add that item to the list... :\ no need for all that stuff
    Light travels faster than sound. That's why most people seem bright until you hear them speak.

  8. #7
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Oops thanks for that little error fix Kevin, turns out I had the the fail logic.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  9. #8
    nathanael890's Avatar
    Join Date
    Aug 2008
    Gender
    male
    Posts
    158
    Reputation
    13
    Thanks
    46
    My Mood
    Bored
    thanks for the codes guys. I just tried to create my program for managing a forum because I'm also a moderator of it. so I want to record my status on it ^^

    *Solved

Similar Threads

  1. Please help me i want the boxes code and dunno how i use them plss tell me
    By willeman in forum Combat Arms Coding Help & Discussion
    Replies: 1
    Last Post: 07-19-2011, 03:15 PM
  2. [HELP] Adding new items in QChaosZombieMod in shop
    By xurple in forum Call of Duty Modern Warfare 2 GSC Modding Help/Discussion
    Replies: 4
    Last Post: 09-05-2010, 10:04 AM
  3. Replies: 4
    Last Post: 06-13-2010, 01:31 PM
  4. Hello! i need help with the source code.
    By LatinHacker in forum Combat Arms Help
    Replies: 3
    Last Post: 05-14-2010, 10:32 PM
  5. need the game code install help!
    By tricks1 in forum Call of Duty Modern Warfare Help
    Replies: 4
    Last Post: 04-21-2010, 10:06 AM