-
Feb 20th, 2017, 09:46 AM
#1
Thread Starter
Lively Member
[RESOLVED] edit Line item in a listview
I have a listview that the end user searches for a job number. I have it working for the most part, just need to make some more tweaks.
What I want to do is set it up for the end user to click to highlight the particular line item an click an Edit button. (or if we can set it up to double click the line item) Once they click the button (or double click), it brings up another form prepopulated with the data in the listview. Then the user can make changes to the order and save.
I have searched around trying to find an example (of double click) and found and tried this code. If I try to double click the line item in the listview, it does not open the new form. If it is not selected, I do get the msg box "Please select an item"
Code:
Dim TheSelectedItem As ListViewItem
Private Sub lstSearch_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstSearch.DoubleClick
If Me.lstSearch.SelectedItems.Count > 0 Then
TheSelectedItem = Me.lstSearch.SelectedItems(0)
editOrder.txtSalesOrder.Text = TheSelectedItem.Text
editOrder.cboRoom.Text = TheSelectedItem.SubItems(0).Text
editOrder.cboSequence.Text = TheSelectedItem.SubItems(1).Text
editOrder.txtJobName.Text = TheSelectedItem.SubItems(2).Text
End If
End Sub
Private Sub cmdEdit_Click(sender As Object, e As EventArgs) Handles cmdEdit.Click
If Not IsNothing(TheSelectedItem) Then
TheSelectedItem.Text = editOrder.txtSalesOrder.Text
TheSelectedItem.SubItems(0).Text = editOrder.cboRoom.Text
TheSelectedItem.SubItems(1).Text = editOrder.cboSequence.Text
TheSelectedItem.SubItems(2).Text = editOrder.txtJobName.Text
TheSelectedItem = Nothing
Else
MessageBox.Show("Please Select an Item")
End If
End Sub
TIA
-
Feb 20th, 2017, 11:22 AM
#2
Thread Starter
Lively Member
Re: edit Line item in a listview
I got the code fixed so that it shows the editOrder form. It is not populating the correct fields in the editOrder. Below is my code.
Code:
Dim TheSelectedItem As ListViewItem
Private Sub lstSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstSearch.Click
If Me.lstSearch.SelectedItems.Count > 0 Then
TheSelectedItem = Me.lstSearch.SelectedItems(0)
editOrder.txtSalesOrder.Text = TheSelectedItem.Text
editOrder.cboRoom.Text = TheSelectedItem.SubItems(0).Text
editOrder.cboSequence.Text = TheSelectedItem.SubItems(1).Text
editOrder.txtJobName.Text = TheSelectedItem.SubItems(2).Text
editOrder.lblEstimatedDelivery.Text = TheSelectedItem.SubItems(3).Text
End If
End Sub
Private Sub cmdEdit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdEdit.Click
If Not IsNothing(TheSelectedItem) Then
editOrder.Show()
TheSelectedItem.Text = editOrder.txtSalesOrder.Text
TheSelectedItem.SubItems(0).Text = editOrder.cboRoom.Text
TheSelectedItem.SubItems(1).Text = editOrder.cboSequence.Text
TheSelectedItem.SubItems(2).Text = editOrder.txtJobName.Text
TheSelectedItem.SubItems(3).Text = editOrder.lblEstimatedDelivery.Text
TheSelectedItem = Nothing
Else
MessageBox.Show("Please Select an Item")
End If
End Sub
The sales order is going into the correct location and it is filling Room # as well.
Sequence number is filling in Job Name
The job name is filling Estimated Delivery Date
Sequence number is getting the Room number.
TIA
-
Feb 20th, 2017, 02:01 PM
#3
Hyperactive Member
Re: edit Line item in a listview
if your problem is fixed Mark thread as resolved.
Please Mark your Thread "Resolved", if the problem is solved & Rate those who have helped you
-
Feb 20th, 2017, 03:30 PM
#4
Re: edit Line item in a listview
Originally Posted by jmyersnc
The sales order is going into the correct location and it is filling Room # as well.
Sequence number is filling in Job Name
The job name is filling Estimated Delivery Date
Sequence number is getting the Room number.
That's because TheSelectedItem.Text is same as TheSelectedItem.SubItems(0).Text, so all you need is to fix SubItem index
Code:
editOrder.cboRoom.Text = TheSelectedItem.SubItems(1).Text' 1 insted of 0
editOrder.cboSequence.Text = TheSelectedItem.SubItems(2).Text
editOrder.txtJobName.Text = TheSelectedItem.SubItems(3).Text
editOrder.lblEstimatedDelivery.Text = TheSelectedItem.SubItems(4).Text
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
|