|
-
Nov 8th, 2006, 06:07 AM
#1
Thread Starter
New Member
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
-
Nov 8th, 2006, 09:24 AM
#2
Hyperactive Member
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:
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
-
Nov 8th, 2006, 09:46 AM
#3
Thread Starter
New Member
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?
-
Nov 8th, 2006, 09:49 AM
#4
Thread Starter
New Member
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
-
Nov 8th, 2006, 10:06 AM
#5
Re: Editing Informaiton on List View
 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.
-
Nov 8th, 2006, 10:30 AM
#6
Thread Starter
New Member
Re: Editing Informaiton on List View
hi there, sorry i have no idea what to do with that can you help
-
Nov 8th, 2006, 12:29 PM
#7
Re: Editing Informaiton on List View
 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:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'This is used to load some dummy data to listview1 for testing purposes
'ListView1 properties are set to: View = Details, FullRowSelect = True, MultiSelect = True
ListView1.Columns.Add("First", 60, HorizontalAlignment.Left)
ListView1.Columns.Add("Last", 60, HorizontalAlignment.Right)
Dim itm As ListViewItem
For i As Integer = 0 To 5
itm = New ListViewItem(New String() {"First_" & i, "Last_" & i})
ListView1.Items.Add(itm)
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
'Create a new instance of Form2 and pass values to it for each
'selected item in listview1
For Each itm As ListViewItem In ListView1.SelectedItems
Dim frm2 As New Form2
'Pass the index of selected item to this instance of Form2
frm2.ItemIndex = itm.Index
'Pass the actual item to this instance of Form2
frm2.LvwItem = itm
'Set the current instance of Form1 as the Owner of frm2
frm2.Owner = Me
'Show this instance of Form2
frm2.Show()
Next
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:
Private _ItemIndex As Integer
Private _LvwItem As ListViewItem
Public Property ItemIndex() As Integer
Get
Return _ItemIndex
End Get
Set(ByVal Value As Integer)
_ItemIndex = Value
End Set
End Property
Public Property LvwItem() As ListViewItem
Get
Return _LvwItem
End Get
Set(ByVal Value As ListViewItem)
_LvwItem = Value
End Set
End Property
Private Sub Form2_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
If Not _LvwItem Is Nothing Then
TextBox1.Text = _LvwItem.SubItems(0).Text
TextBox2.Text = _LvwItem.SubItems(1).Text
End If
End Sub
Private Sub Form2_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
'Create a new listViewItem with the updated info from textboxes
'and assign it back to the same listview1 item in Form1
Dim lvwItm As New ListViewItem(New String() {TextBox1.Text, TextBox2.Text})
CType(Me.Owner, Form1).ListView1.Items(_ItemIndex) = lvwItm
End Sub
-
Nov 10th, 2006, 06:23 AM
#8
Thread Starter
New Member
Re: Editing Informaiton on List View
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
|