-
July 13th, 2012, 12:16 PM
#1
Output ListView Row to a Label
I've tried looking this up but nobody has a tutorial that clears this issue up for me.
I have a listview containing 3 columns and a user-selected number of rows. I would like to (on btn_click) add all rows from a this ListView to a Label. Here's the catch...I would like to check these items against the items in a database and pull some more information about these parts along with the info that is already in the ListView.
But because the first column in my ListView is an Item (not subitem) and for other reasons I do not understand, the output label only displays the second column.
This is what I have so far:
Code:
Dim counter As Integer
Private Sub AddPLCbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddPLCbtn.Click
'Checks for which items have been entered on the PLC tab
'CheckforEnteredPLC()
'************
If PLCTableList.CheckedItems.Count = 1 Then
Select Case counter
Case 1
lblBomEnteredItems.Text = PLCTableList.SelectedItems(-1).Text
End Select
counter += 1
'This bit of code is so that you loop round and start at 1 again
If counter > 1 Then
counter = 1
End If
Else
MsgBox("You must select an item in order to continue")
End If
'**************
iAddedIOGroupID = iAddedIOGroupID + 1
With Me.PLCTableList
Dim i As Integer
For Each item As ListViewItem In PLCTableList.CheckedItems
i = item.Index
Next
Dim innercounter As Integer = 0
For Each subItem As ListViewItem.ListViewSubItem In PLCTableList.Items(i).SubItems
Dim myString As String = PLCTableList.Items(i).SubItems(innercounter).Text
Select Case innercounter
Case 1
lblBomEnteredItems.Text = myString
End Select
innercounter += 1
Next
End With
end sub
Thank you for any help you may offer
-
July 13th, 2012, 07:16 PM
#2
Re: Output ListView Row to a Label
This whole structure is pretty far off
Code:
For Each item As ListViewItem In PLCTableList.CheckedItems
i = item.Index
Next
Dim innercounter As Integer = 0
For Each subItem As ListViewItem.ListViewSubItem In PLCTableList.Items(i).SubItems
Dim myString As String = PLCTableList.Items(i).SubItems(innercounter).Text
Select Case innercounter
Case 1
lblBomEnteredItems.Text = myString
End Select
innercounter += 1
Next
You may want something more like this for your loop structure though I assume you would want linefeeds or seperators in there as well.
Code:
For Each tmpItem As ListViewItem In PLCTableList.CheckedItems
Dim myString As String =tmpitem.text
For Each tmpSubItem As ListViewItem.ListViewSubItem In tmpItem.SubItems
myString &= tmpsubitem.Text
Next
lblBomEnteredItems.Text &= myString
Next
Always use [code][/code] tags when posting code.
-
July 16th, 2012, 08:17 AM
#3
Re: Output ListView Row to a Label
Thank you.
That worked! I'm going to attempt checking these items against those in the DB before output to the label and try to configure some seperation within the label.
-
July 16th, 2012, 11:50 AM
#4
Re: Output ListView Row to a Label
Code:
Private Sub AddPLCbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddPLCbtn.Click
'Checks for which items have been entered on the PLC tab
With Me.PLCTableList
For Each tmpItem As ListViewItem In PLCTableList.CheckedItems
Dim myString As String = ""
Try
Using udtconn As New SqlConnection(sBoMConnectionString)
Dim daPLC As New SqlDataAdapter(New SqlCommand("Select * from PLC where Part_Number = '" & tmpItem.Text & "'", udtconn))
Dim dsPLC As New DataSet
dsPLC.Tables.Add("PLC")
daPLC.Fill(dsPLC.Tables("PLC"))
Me.BoMDataSetBindingSource.DataSource = dsPLC.Tables("PLC")
daPLC.Fill(dsPLC)
'Creates new plc class with the information that was pulled from the database
Dim newPLC As New clsPLC()
newPLC.PartType() = CType(dsPLC.Tables("PLC").Rows(0).Item("Part_Type"), String)
newPLC.PartSubType() = CType(dsPLC.Tables("PLC").Rows(0).Item("Part_Sub_Type"), String)
newPLC.PLCPartNumber = CType(dsPLC.Tables("PLC").Rows(0).Item("Part_Number"), String)
newPLC.PLCManufacturer = CType(dsPLC.Tables("PLC").Rows(0).Item("Manufacturer"), String)
newPLC.PLCVendor = CType(dsPLC.Tables("PLC").Rows(0).Item("Vendor"), String)
newPLC.PLCDescription = CType(dsPLC.Tables("PLC").Rows(0).Item("Description"), String)
'newPLC.PLCQuantity = tmpitem.subitem.tostring
newPLC.PLCPrice = CType(dsPLC.Tables("PLC").Rows(0).Item("Price"), Double)
newPLC.AddedGroupID = iAddedIOGroupID
lstPLC.Add(newPLC)
End Using
Catch ex As Exception
'An error occured while pulling data
End Try
Next
End With
' Load onto BoM
LoadCurrentBoM()
'Clears the plc tab
btnClearPLC_Click(Nothing, Nothing)
End Sub
This is what I have now. It pulls data from the database based upon the unique identifier in the checked row and the LoadCurrentBoM() method organizes it within the label.
Now my issue is with the commented out "newPLC" row. How may I display the subitem QTY (third column in the ListView) in the label as it is in the ListView? With generalized naming(tmpitem.subitem) how might this work?
Thanks.
-
July 16th, 2012, 02:10 PM
#5
Re: Output ListView Row to a Label
I've got this figured out now.
Code:
newPLC.PLCQuantity = tmpItem.SubItems(2).Text
Much more simple than I thought.
But the Part_Number will not display even though everything else will display. I was wondering if there were any errors to be found in the code I provided regarding the Part Number (not including database issues because there are none).
Thanks for any help you might offer!
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
|