When the project is created, add two
buttons and a text box to the form. Set the properties of the controls as follows:
??‘ Button1
??‘ Name - cmdOK
??‘ Text - OK
??‘ Button2
??‘ Name - cmdCancel
??‘ Text - Cancel
??‘ TextBox1
??‘ Name - txtResults1
??‘ Multiline - True
??‘ ScrollBars - Vertical
??‘ TextBox2
??‘ Name - txtResults2
??‘ Multiline - True
??‘ ScrollBars - Vertical
??‘ TextBox3
??‘ Name - txtResults3
??‘ Multiline - True
??‘ ScrollBars - Vertical
In the Click() event of the Cancel button, enter the following code:
Application.Exit()
192
Chapter 9: LINQ to XML and Visual Basic .NET
Next, in the Click() event of the OK button, place the following code:
Dim emp As XElement = XElement.Load("c:\Wrox\Linq\Chapter 9\Employees.xml")
Dim tree As XElement = New XElement("Root", _
From el In emp.Elements() Select el)
??™ Load these changes into the first text box
Me.txtResults1.Text = tree.ToString()
??™ Next, let??™s just grab the first employee
Dim empPart as XElement = (From treePart In _
tree.Eleemnts("Employees") Select treePart).
Pages:
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325