Results 1 to 8 of 8

Thread: Editing Informaiton on List View

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    7

    Editing Informaiton on List View

    Sorry i am a relatively inexperienced programmer requiring urgent help,

    I am trying to select an appropriate field in list view then for a second form to appear and the data entered in this form i want to replace by what was previously selected,.

    Have got data to add ok just not edit see code below area in colour is area im having dificulty with, thanks for any help in advance


    Private Sub bttnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnadd.Click
    ' this sub takes the informaiton that the user has inputed into frmaddedit and adds it to the list view under its approprate heading in spylist in the form display screen
    If Me.Text = "Add" Then
    Dim spyinfo As Array

    dispscreen.spylist.Items.Add(fstnam.Text)
    Dim i As Integer = 0
    i = dispscreen.spylist.Items.Count - 1
    dispscreen.spylist.Items.Item(i).SubItems.Add(surnam.Text)
    dispscreen.spylist.Items.Item(i).SubItems.Add(age1.Text)
    dispscreen.spylist.Items.Item(i).SubItems.Add(cdenam.Text)
    dispscreen.spylist.Items.Item(i).SubItems.Add(specskil.Text)
    dispscreen.spylist.Items.Item(i).SubItems.Add(sex.Text)
    dispscreen.spylist.Items.Item(i).SubItems.Add(distinmar.Text)
    dispscreen.spylist.Items.Item(i).SubItems.Add(swbank.Text)

    Me.Hide()
    Else
    ' this part of the sub takes information that has been inputed into edit screen when the edit button has been clicked and replaces it by what was previously selected
    If Me.Text = "Edit" Then
    'dispscreen.spylist.Items(dispscreen.spylist.SelectedIndices.Item(0))
    Dim i As Integer = 0

    i = dispscreen.spylist.Items.Count - 1
    dispscreen.spylist.SelectedItems.Item(i).SubItems.Add(fstnam.Text)
    dispscreen.spylist.SelectedItems.Item(i).SubItems.add(surnam.Text)
    dispscreen.spylist.Items.Item(i).SubItems.Add(age1.Text)
    dispscreen.spylist.Items.Item(i).SubItems.Add(cdenam.Text)
    dispscreen.spylist.Items.Item(i).SubItems.Add(specskil.Text)
    dispscreen.spylist.Items.Item(i).SubItems.Add(sex.Text)
    dispscreen.spylist.Items.Item(i).SubItems.Add(distinmar.Text)
    dispscreen.spylist.Items.Item(i).SubItems.Add(swbank.Text)

    Me.Hide()
    End If
    End If

    'this part of the sub sets the input screen back to a blank value it basically clears the formadd back to a blank state ready for the next spy to be added
    fstnam.Text = ""
    surnam.Text = ""
    age1.Text = ""
    cdenam.Text = ""
    specskil.Text = ""
    sex.Text = ""
    distinmar.Text = ""
    swbank.Text = ""
    End Sub

  2. #2
    Hyperactive Member
    Join Date
    May 2005
    Posts
    262

    Re: Editing Informaiton on List View

    First, post using the VBCODE /VBCODE tags it makes it easier to read

    second, i dont think i really understand what you want.. whats not happening or any errors you're getting?

    seems like you're trying to select an edit button and bring that "spys" info to the listview? where are you storing all this information?

    VB Code:
    1. Private Sub bttnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnadd.Click
    2. ' this sub takes the informaiton that the user has inputed into frmaddedit and adds it to the list view under its approprate heading in spylist in the form display screen
    3. If Me.Text = "Add" Then
    4. Dim spyinfo As Array
    5.  
    6. dispscreen.spylist.Items.Add(fstnam.Text)
    7. Dim i As Integer = 0
    8. i = dispscreen.spylist.Items.Count - 1
    9. dispscreen.spylist.Items.Item(i).SubItems.Add(surnam.Text)
    10. dispscreen.spylist.Items.Item(i).SubItems.Add(age1.Text)
    11. dispscreen.spylist.Items.Item(i).SubItems.Add(cdenam.Text)
    12. dispscreen.spylist.Items.Item(i).SubItems.Add(specskil.Text)
    13. dispscreen.spylist.Items.Item(i).SubItems.Add(sex.Text)
    14. dispscreen.spylist.Items.Item(i).SubItems.Add(distinmar.Text)
    15. dispscreen.spylist.Items.Item(i).SubItems.Add(swbank.Text)
    16.  
    17. Me.Hide()
    18. Else
    19. ' this part of the sub takes information that has been inputed into edit screen when the edit button has been clicked and replaces it by what was previously selected
    20. If Me.Text = "Edit" Then
    21. 'dispscreen.spylist.Items(dispscreen.spylist.SelectedIndices.Item(0))
    22. Dim i As Integer = 0
    23.  
    24. i = dispscreen.spylist.Items.Count - 1
    25. dispscreen.spylist.SelectedItems.Item(i).SubItems.Add(fstnam.Text)
    26. dispscreen.spylist.SelectedItems.Item(i).SubItems.add(surnam.Text)
    27. dispscreen.spylist.Items.Item(i).SubItems.Add(age1.Text)
    28. dispscreen.spylist.Items.Item(i).SubItems.Add(cdenam.Text)
    29. dispscreen.spylist.Items.Item(i).SubItems.Add(specskil.Text)
    30. dispscreen.spylist.Items.Item(i).SubItems.Add(sex.Text)
    31. dispscreen.spylist.Items.Item(i).SubItems.Add(distinmar.Text)
    32. dispscreen.spylist.Items.Item(i).SubItems.Add(swbank.Text)
    33.  
    34. Me.Hide()
    35. End If
    36. End If
    37. 'this part of the sub sets the input screen back to a blank value it basically clears the formadd back to a blank state ready for the next spy to be added
    38. fstnam.Text = ""
    39. surnam.Text = ""
    40. age1.Text = ""
    41. cdenam.Text = ""
    42. specskil.Text = ""
    43. sex.Text = ""
    44. distinmar.Text = ""
    45. swbank.Text = ""
    46. End Sub

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    7

    Re: Editing Informaiton on List View

    hi, data is being stored to the listview for now, eventually will export this data to txt file. basically when the edit button is clicked i want a form to appear(which i have got) then all the informaiton put into this form has to replace what was previously there any ideas?

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    7

    Re: Editing Informaiton on List View

    sorry, just a sub note, everything in the code after the "else" statment is rubbish i was jsut tryng things out here thanks

  5. #5
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Editing Informaiton on List View

    Quote Originally Posted by bsm1
    hi, data is being stored to the listview for now, eventually will export this data to txt file. basically when the edit button is clicked i want a form to appear(which i have got) then all the informaiton put into this form has to replace what was previously there any ideas?
    In button edit click event do:
    1. check to see if any thing is selected in the listview.
    2. If something is selected... Pull that item's data (should include the index of the selected item too in case your user select multiple items) and pass it to the 2nd form where the user will do the edit.
    3. In the 2nd form load event, load the data passed from the main form accordingly.
    4. Now that the user have done editing and close the form... Back in the main form, you need to read back the info from the closing form including the index number, and update your listview item accordingly.
    If you don't know how to do any of these, please say so... I'll be glad to give help where I can.

  6. #6

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    7

    Unhappy Re: Editing Informaiton on List View

    hi there, sorry i have no idea what to do with that can you help

  7. #7
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Editing Informaiton on List View

    Quote Originally Posted by bsm1
    hi there, sorry i have no idea what to do with that can you help
    Here a quick example I just made... Hope it helps.
    Form1 has a ListView1, and a Button1 (click to edit selected items in ListView1)
    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.  
    3.         'This is used to load some dummy data to listview1 for testing purposes
    4.         'ListView1 properties are set to: View = Details, FullRowSelect = True, MultiSelect = True
    5.         ListView1.Columns.Add("First", 60, HorizontalAlignment.Left)
    6.         ListView1.Columns.Add("Last", 60, HorizontalAlignment.Right)
    7.         Dim itm As ListViewItem
    8.         For i As Integer = 0 To 5
    9.             itm = New ListViewItem(New String() {"First_" & i, "Last_" & i})
    10.             ListView1.Items.Add(itm)
    11.         Next
    12.     End Sub
    13.  
    14.     Private Sub Button1_Click(ByVal sender As System.Object, _
    15.                               ByVal e As System.EventArgs) Handles Button1.Click
    16.         'Create a new instance of Form2 and pass values to it for each
    17.         'selected item in listview1
    18.         For Each itm As ListViewItem In ListView1.SelectedItems
    19.             Dim frm2 As New Form2
    20.             'Pass the index of selected item to this instance of Form2
    21.             frm2.ItemIndex = itm.Index
    22.             'Pass the actual item to this instance of Form2
    23.             frm2.LvwItem = itm
    24.             'Set the current instance of Form1 as the Owner of frm2
    25.             frm2.Owner = Me
    26.             'Show this instance of Form2
    27.             frm2.Show()
    28.         Next
    29.     End Sub
    And the code for Form2... Form2 has only 2 textboxes (because an item in Form1's ListView1 has only 2 subitems...)
    VB Code:
    1. Private _ItemIndex As Integer
    2.     Private _LvwItem As ListViewItem
    3.  
    4.     Public Property ItemIndex() As Integer
    5.         Get
    6.             Return _ItemIndex
    7.         End Get
    8.         Set(ByVal Value As Integer)
    9.             _ItemIndex = Value
    10.         End Set
    11.     End Property
    12.  
    13.     Public Property LvwItem() As ListViewItem
    14.         Get
    15.             Return _LvwItem
    16.         End Get
    17.         Set(ByVal Value As ListViewItem)
    18.             _LvwItem = Value
    19.         End Set
    20.     End Property
    21.  
    22.     Private Sub Form2_Load(ByVal sender As Object, _
    23.                            ByVal e As System.EventArgs) _
    24.                            Handles MyBase.Load
    25.         If Not _LvwItem Is Nothing Then
    26.             TextBox1.Text = _LvwItem.SubItems(0).Text
    27.             TextBox2.Text = _LvwItem.SubItems(1).Text
    28.         End If
    29.  
    30.     End Sub
    31.  
    32.     Private Sub Form2_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    33.         'Create a new listViewItem with the updated info from textboxes
    34.         'and assign it back to the same listview1 item in Form1
    35.         Dim lvwItm As New ListViewItem(New String() {TextBox1.Text, TextBox2.Text})
    36.         CType(Me.Owner, Form1).ListView1.Items(_ItemIndex) = lvwItm
    37.     End Sub

  8. #8

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    7

    Re: Editing Informaiton on List View

    Thanks problem solved

Posting Permissions

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



Click Here to Expand Forum to Full Width