Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Deleting a Positon in an array

Deleting a Positon in an array

Scheduled Pinned Locked Moved Visual Basic
helpquestionhtmldata-structures
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    harrysk
    wrote on last edited by
    #1

    Hello i've got a problem with deleting a postion with deleting the current (or selected) member (view my member form in the project link below). http://rapidshare.de/files/1970958/FP2_FilmStore.zip.html I can add and view next or previous members but how do i delete the currently selected member???? Any ideas as im totally stuck and have no idea.

    T 1 Reply Last reply
    0
    • H harrysk

      Hello i've got a problem with deleting a postion with deleting the current (or selected) member (view my member form in the project link below). http://rapidshare.de/files/1970958/FP2_FilmStore.zip.html I can add and view next or previous members but how do i delete the currently selected member???? Any ideas as im totally stuck and have no idea.

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      what are you talking about ? combobox ? listbox ? datagrid ? does the control have an arraylist as datasource ? ps:there is nothing comparable to what you talk about in the link you provided. is the link broken ?


      TOXCCT >>> GEII power
      [toxcct][VisualCalc]

      H 1 Reply Last reply
      0
      • T toxcct

        what are you talking about ? combobox ? listbox ? datagrid ? does the control have an arraylist as datasource ? ps:there is nothing comparable to what you talk about in the link you provided. is the link broken ?


        TOXCCT >>> GEII power
        [toxcct][VisualCalc]

        H Offline
        H Offline
        harrysk
        wrote on last edited by
        #3

        For the link go to FREE at the bottom of the page, the next page (again at the bottom) you can download my uploaded app. And the Members (control) are stored in arraylist. Although there is nothing in there to start with. The user enters member details (and films) when the app is run.

        R 1 Reply Last reply
        0
        • H harrysk

          For the link go to FREE at the bottom of the page, the next page (again at the bottom) you can download my uploaded app. And the Members (control) are stored in arraylist. Although there is nothing in there to start with. The user enters member details (and films) when the app is run.

          R Offline
          R Offline
          rudy net
          wrote on last edited by
          #4

          You can use class ArrayList. It has a method RemoveAt(). Or if you prefer to stay with your current array then you can use Array.Copy to copy your array to another one then copy back. Array.Copy allows you to specify how many objects to copy, what positions to copy, etc; however, it seems like a bad solution. I prefer ArrayList but the downside of using ArrayList is that you have to cast from object to your class when you get an object from the array.

          H 1 Reply Last reply
          0
          • R rudy net

            You can use class ArrayList. It has a method RemoveAt(). Or if you prefer to stay with your current array then you can use Array.Copy to copy your array to another one then copy back. Array.Copy allows you to specify how many objects to copy, what positions to copy, etc; however, it seems like a bad solution. I prefer ArrayList but the downside of using ArrayList is that you have to cast from object to your class when you get an object from the array.

            H Offline
            H Offline
            harrysk
            wrote on last edited by
            #5

            Can you give me an example of the array.copy as i'm a newbie also how would i know which one to delete??? If you can would you be able to give an example?

            T R 2 Replies Last reply
            0
            • H harrysk

              Can you give me an example of the array.copy as i'm a newbie also how would i know which one to delete??? If you can would you be able to give an example?

              T Offline
              T Offline
              toxcct
              wrote on last edited by
              #6

              hey guy, you will have to be more clear (2nd time !!!) where do you get the selected item from ? a combobox ? a listbox ? a datagrid ? i ask this because an arraylist cannot be displayed directly on a form as it is not a control (it is only a container class). SO, i understand you want to delete an element from an arraylist with its index, but where do you get its index from ?? (see the question posted previously on this post)...


              TOXCCT >>> GEII power
              [toxcct][VisualCalc]

              H 1 Reply Last reply
              0
              • H harrysk

                Can you give me an example of the array.copy as i'm a newbie also how would i know which one to delete??? If you can would you be able to give an example?

                R Offline
                R Offline
                rudy net
                wrote on last edited by
                #7

                Here is the code using Array.Copy, although it's probably easier to create a loop and copy all elements in an array except the one you want to delete. Dim str As String = "This is my original string" Dim originalArray() As String = str.Split(" ") 'now to remove the fourth word: (index 3) Dim indexToRemove = 3 Dim newArray(originalArray.Length - 2) As String Dim numElementsToCopyFirst = indexToRemove 'copy everything up to index right before the element to be removed Array.Copy(originalArray, 0, newArray, 0, numElementsToCopyFirst) Dim numElementsToCopySecond = originalArray.Length - indexToRemove - 1 Array.Copy(originalArray, indexToRemove + 1, newArray, numElementsToCopyFirst, numElementsToCopySecond) 'now replace original array ReDim originalArray(newArray.Length - 1) Array.Copy(newArray, originalArray, newArray.Length)

                1 Reply Last reply
                0
                • T toxcct

                  hey guy, you will have to be more clear (2nd time !!!) where do you get the selected item from ? a combobox ? a listbox ? a datagrid ? i ask this because an arraylist cannot be displayed directly on a form as it is not a control (it is only a container class). SO, i understand you want to delete an element from an arraylist with its index, but where do you get its index from ?? (see the question posted previously on this post)...


                  TOXCCT >>> GEII power
                  [toxcct][VisualCalc]

                  H Offline
                  H Offline
                  harrysk
                  wrote on last edited by
                  #8

                  sorry, the member is select using a next/previous button to switch between members. So for example when i click next, the textboxes will fill with the info of that particular member; Name, address, postcode, ID etc.

                  T 1 Reply Last reply
                  0
                  • H harrysk

                    sorry, the member is select using a next/previous button to switch between members. So for example when i click next, the textboxes will fill with the info of that particular member; Name, address, postcode, ID etc.

                    T Offline
                    T Offline
                    toxcct
                    wrote on last edited by
                    #9

                    harrysk wrote: sorry, the member is select using a next/previous button to switch between members. ok, so if i well understand (you explaination is not well detailled yet but i start understanding what you mean), you have a textbox that display a part of a list, and you move into that list with Previous/Next buttons. so, if you reach doing this, you also have an index variable to point to the element you want to display, right ? this way, your index variable is positioned on the current element, agree ? so, you can do the easy following thing :

                    Dim MyList As ArrayList
                    Dim MyIndex As Integer = 0

                    'You fill your list...

                    'You use your list...

                    'Then, you remove the current element :
                    MyList.RemoveAt(MyIndex)

                    and that's all... was is so complicated to find by yourself ? maybe you don't know where to find ?! well, you go to the MSDN, filter by Visual Basic, then search for ArrayList (its the members), so read there what seems to answer to your problem... cheers,


                    TOXCCT >>> GEII power
                    [toxcct][VisualCalc]

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups