Home All Groups Group Topic Archive Search About
Author
24 Apr 2006 8:02 AM
trevor.niemack@za.syspro.com
I have just done an application that will allow you to insert XML into
a text box then do an xpath query to return the values against the
node. I am just a beginner so for me this is really cool but I want to
be able to get the nodes that returned information to be highlighted.
This is an example of my code at current:
Imports System.Xml

Public Class Form1
    Dim used As Boolean
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
        Dim xmlstring As String = TextBox1.Text
'"<root><item>Trevor</item><item>Niemack</item><item>27 years
old</item><item>Married</item><item>Employed</item></root>"
        Dim doc As New XmlDocument
        doc.LoadXml(xmlstring)
        Dim node As XmlNode

        If used = True Then
            used = False
        End If
        For Each node In doc.SelectNodes(TextBox3.Text)
            ListBox1.Items.Add(node.InnerText)
            used = True
        Next

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
        ListBox1.Items.Clear()
        used = False
    End Sub
End Class

Author
24 Apr 2006 9:17 AM
Cerebrus
Hi Trevor,

You'll need to use a RichTextBox control if you want to show the
returned nodes in Bold. A simple TextBox won't do. You can drag it onto
your form from the Toolbox.

HTH,

Regards,

Cerebrus.
Author
24 Apr 2006 9:32 AM
trevor.niemack@za.syspro.com
Thank you for the suggestion but now that I have inserted the
richtextbox I still am not sure of how to only bold selected nodes.
Author
24 Apr 2006 2:11 PM
Cerebrus
I'm sorry, I assumed you would have worked out that logic... Never
mind, here is one possible way :

1. You'll have to search for that particular word in the Text of the
RichTextBox(RTB), using the IndexOf method.
When you do find it, store the index position :

Dim idx as integer = RTB.Text.IndexOf(wordToFind, 0)

2. Select that particular word.

RTB.Select(idx, wordToFind.Length)

3. Make changes to it's Font :

RTB.SelectionFont = New Font(RTB.Font, FontStyle.Underline)

I guess that should do it. I've typed it here itself, so please watch
for syntax.

Regards,

Cerebrus.
Author
24 Apr 2006 3:00 PM
Peter Proost
I can now see that my post was a bit late and Cerebrus already answered, but
that's because I forget to press F5 before posting :-)

Greetz Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

Show quoteHide quote
"Cerebrus" <zorg***@sify.com> schreef in bericht
news:1145887919.680968.114000@e56g2000cwe.googlegroups.com...
> I'm sorry, I assumed you would have worked out that logic... Never
> mind, here is one possible way :
>
> 1. You'll have to search for that particular word in the Text of the
> RichTextBox(RTB), using the IndexOf method.
> When you do find it, store the index position :
>
> Dim idx as integer = RTB.Text.IndexOf(wordToFind, 0)
>
> 2. Select that particular word.
>
> RTB.Select(idx, wordToFind.Length)
>
> 3. Make changes to it's Font :
>
> RTB.SelectionFont = New Font(RTB.Font, FontStyle.Underline)
>
> I guess that should do it. I've typed it here itself, so please watch
> for syntax.
>
> Regards,
>
> Cerebrus.
>
Author
24 Apr 2006 3:15 PM
Cerebrus
Lol, Peter... Happens to me all the time...

Regards,

Cerebrus.
Author
24 Apr 2006 2:58 PM
Peter Proost
Hi have a look at the SelectionFont property of the richtextbox that should
do what you want

Greetz Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

<trevor.niem***@za.syspro.com> schreef in bericht
Show quoteHide quote
news:1145871159.171656.55350@t31g2000cwb.googlegroups.com...
> Thank you for the suggestion but now that I have inserted the
> richtextbox I still am not sure of how to only bold selected nodes.
>