Sep
30
Written by:
Steve Gray
9/30/2009 1:09 PM
The task is to create a LIST of MYCLASS, and to be able to search that generic list and return matches. All the examples that I found talked about being able to search a list (of String), but I needed to be able to search a List (of MyClass)
In the form load we create and populate our list.
In the button event, I show two different searches, one using List.Find and one using List.FindAll.
List.Find returns zero or one instances of MyClass, List.FindAll will return zero to many instances in a List(of MyClass)
Public Class Form1
Public Class IVQuantityHelperUofM
Public UofM As String
Public QtyInBase As Double
Public Sub New(ByVal uofm As String, ByVal qtyinbase As Double)
Me.UofM = uofm
Me.QtyInBase = qtyinbase
End Sub
End Class
Private IVQuantityHelperUofMs As New List(Of IVQuantityHelperUofM)
Private FindMyType1 As String
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
IVQuantityHelperUofMs.Add(New IVQuantityHelperUofM("Each", 1))
IVQuantityHelperUofMs.Add(New IVQuantityHelperUofM("Box", 16))
IVQuantityHelperUofMs.Add(New IVQuantityHelperUofM("Pallet", 256))
IVQuantityHelperUofMs.Add(New IVQuantityHelperUofM("Pallet", 512))
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
FindMyType1 = "Box"
Dim match As IVQuantityHelperUofM = _
IVQuantityHelperUofMs.Find(AddressOf MatchMyType1)
FindMyType1 = "Pallet"
Dim matches As List(Of IVQuantityHelperUofM) = _
IVQuantityHelperUofMs.FindAll(AddressOf MatchMyType1)
End Sub
Private Function MatchMyType1(ByVal sc As IVQuantityHelperUofM) As Boolean
Return sc.UofM = FindMyType1
End Function
End Class
Edit:
Steve Endow suggested this:
Dim xmlDoc As New Xml.XmlDocument
Dim xmlNode As Xml.XmlNode
Dim myXML As String = RichTextBox1.Text.Trim
xmlDoc.LoadXml(myXML)
xmlNode = xmlDoc.SelectSingleNode("//taSopLineIvcInsert[ITEMNMBR='101']")
xmlNode.ParentNode.RemoveChild(xmlNode)
As always, I welcome your comments!