Click here to Skip to main content
15,911,531 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: please how can i make my own controls ?? Pin
Mohammed Amine24-Apr-06 16:48
Mohammed Amine24-Apr-06 16:48 
GeneralRe: please how can i make my own controls ?? Pin
Dave Kreskowiak24-Apr-06 17:29
mveDave Kreskowiak24-Apr-06 17:29 
QuestionPocket PC error Pin
dptalt24-Apr-06 10:40
dptalt24-Apr-06 10:40 
QuestionVB Generated Code in Designer.vb Pin
MikeUPMC24-Apr-06 9:40
MikeUPMC24-Apr-06 9:40 
Questionupgrading a dll Pin
shrinker11124-Apr-06 6:00
shrinker11124-Apr-06 6:00 
QuestionDisable form while dialog is open Pin
G7236024-Apr-06 5:00
G7236024-Apr-06 5:00 
AnswerRe: Disable form while dialog is open Pin
Dave Kreskowiak24-Apr-06 8:49
mveDave Kreskowiak24-Apr-06 8:49 
QuestionParse xmldocument attributes(not elements) and display in treeview, then save treeview into xmldocument Pin
tanya foster24-Apr-06 3:17
tanya foster24-Apr-06 3:17 
------------Begin Update on my original question

I have been able to successfully store the attribute list in the TreeNode.Tag field in the AddNode function.

I have changed the line of code in AddNode function
inTreeNode.Text = inTreeNode.Text & " " & (attrNode.OuterXml).Trim
TO
inTreeNode.Tag = inTreeNode.Tag & " " & (attrNode.OuterXml).Trim

I do not see the Tag field displayed on the treeview though.

Then I changed the line of code in SaveScreenChangesToFile function
Else
StreamWriterForXml.Write("<" & currentTreeNode.Text & ">")
TO
Else
StreamWriterForXml.Write("<" & currentTreeNode.Text & " " & currentTreeNode.Tag & ">")

-- now I can save the attributes to an output.

But part of my original questions remains... how to display attributes in treeview? Do I HAVE TO populate the TreeNode.text field with attributes to see it? Which will have the effect of complicating my function when I go to write it out as a file. I will have to parse the TreeNode.text field more carefully.

-----------End Update on my original question


Hello,
I am having success with the following code in parsing element's attributes and displaying them in a treeview in visual studio 2003 in a vb.net application. However, when I go to save the treeview using the following code, I do not get any attributes. I am wondering if the way I am storing the attributes in the treeview is the problem. It seems you can display attributes in a treeview but they are still considered elements in a treeview structure. Below is the code I am using. By the way, when I only display elements in the treeview using the code below, there is no problem displaying or saving elements. It is only when I try to add the ability to display and save attributes that my trouble begins because I miss creating ending tags in the saved output and it just gets totally wierd for other things. I am sorry I am not explaining all the output problems when I try to deal with attributes. If anyone is able to shed some light, I will be glad to bore you with the details.
thanks.
tanya


BEGIN code that parses xmldocument into treeview


----- begin button subroutine that fires off reading xml from
------sql server and dumping it into a datatable, then read
------ datatable into an xmldocument

Private Sub ButtonUseThisQuotNumber_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonUseThisQuotNumber.Click
PopulateDataSetWithXml(ComboBoxHelper.Text)
ButtonUseThisQuotNumber.Visible = False
DisplayXmlInTreeView()
TreeViewForXml.Visible = True
End Sub


----------BEGIN SUBSET of PopulateDataSetWithXml procedure used
Try


SQLCommandForQuery = "Select XMLData from webuser.WEB_ORDER_XML where Quote_Num = '" & nQuoteNum & "'"
Dim SqlDataAdapterForPopulateDataTable As New SqlDataAdapter(SQLCommandForQuery, DummyString)
SqlDataAdapterForPopulateDataTable.Fill(DataSetOfData, "TableOfData")
SqlDataAdapterForPopulateDataTable.Dispose()

Dim RowOfData As DataRow = DataSetOfData.Tables(0).Rows(0)
' just for fun I found out it is 42,000+ characters
i = RowOfData(0).ToString.Length


Dim XmlDoc As New Xml.XmlDocument

XmlDoc.LoadXml(RowOfData(0).ToString)

Dim AnXmlNode As XmlNode

AnXmlNode = XmlDoc.DocumentElement


Catch ee As Exception
MsgBox(ee.ToString)
End Try
----------END SUBSET of PopulateDataSetWithXml procedure used


Public Sub DisplayXmlInTreeView()

Dim showAttributes As DialogResult

Try
' SECTION 1. Create a DOM Document and load the XML data into it.

Dim RowOfDataForTreeView As DataRow = DataSetOfData.Tables(0).Rows(0)

domForTreeView.LoadXml(RowOfDataForTreeView(0).ToString)

showAttributes = MessageBox.Show("Do you want attributes displayed?", _
"Attributes in Treeview", MessageBoxButtons.YesNo)

If showAttributes = DialogResult.Yes Then
displayAttributesFlag = True
Else
displayAttributesFlag = False
End If


' SECTION 2. Initialize the treeview control.
TreeViewForXml.Nodes.Clear()
TreeViewForXml.Nodes.Add(New TreeNode(domForTreeView.DocumentElement.Name))
Dim tNode As New TreeNode
tNode = TreeViewForXml.Nodes(0)

' SECTION 3. Populate the TreeView with the DOM nodes.
AddNode(domForTreeView.DocumentElement, tNode)
TreeViewForXml.ExpandAll()


Catch xmlEx As XmlException
MessageBox.Show(xmlEx.Message)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

End Sub

Private Sub AddNode(ByRef inXmlNode As XmlNode, ByRef inTreeNode As TreeNode)
Dim xNode, attrNode As XmlNode
Dim tNode As TreeNode
Dim nodeList As XmlNodeList
Dim i, j As Integer
Dim dumb As String
'Dim attributes As XmlAttributeCollection

' Loop through the XML nodes until the leaf is reached.
' Add the nodes to the TreeView during the looping process.

If inXmlNode.HasChildNodes() Then
nodeList = inXmlNode.ChildNodes


If (displayAttributesFlag = True) Then
If inXmlNode.NodeType = XmlNodeType.Element Then
If inXmlNode.Attributes.Count > 0 Then
' attributes = inXmlNode.Attributes
'dumb = attributes.Item(0).OuterXml
For j = 0 To inXmlNode.Attributes.Count - 1
attrNode = inXmlNode.Attributes(j)
inTreeNode.Text = inTreeNode.Text & " " & (attrNode.OuterXml).Trim
Next
End If
End If
End If


For i = 0 To nodeList.Count - 1
xNode = inXmlNode.ChildNodes(i)
inTreeNode.Nodes.Add(New TreeNode(xNode.Name))
tNode = inTreeNode.Nodes(i)
AddNode(xNode, tNode)
Next
Else

' Here you need to pull the data from the XmlNode based on the
' type of node, whether attribute values are required, and so forth.
inTreeNode.Text = (inXmlNode.OuterXml).Trim
End If
End Sub



END code that parses xmldocument into treeview



---------BEGIN code that reads the treeview into a file

Private Sub ButtonSaveScreenChangesToFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSaveScreenChangesToFile.Click
Dim parentNode As TreeNode
Dim testString As String
Dim xxx As Integer

'get the parent node
parentNode = TreeViewForXml.Nodes(0)

xxx = parentNode.GetNodeCount(True)
MsgBox(parentNode.Text & " has " & xxx & " nodes")

StreamWriterForXml = New StreamWriter("c:\xmlTestOutput.xml")

StreamWriterForXml.Write("<" & parentNode.Text & ">")

SaveScreenChangesToFile(parentNode)
StreamWriterForXml.Close()
MsgBox("Saved output to c:\xmlTestOutput.xml")
End Sub

Private Sub SaveScreenChangesToFile(ByVal nodePassedIn As TreeNode)

Dim tNode As TreeNode
Dim ie As IEnumerator
Dim nodeLabel As String

ie = nodePassedIn.Nodes.GetEnumerator()

nodeLabel = nodePassedIn.Text

While ie.MoveNext()
Dim currentTreeNode As TreeNode
currentTreeNode = ie.Current


If currentTreeNode.GetNodeCount(True) = 0 Then
'this node has no children to parse

StreamWriterForXml.Write(currentTreeNode.Text)
StreamWriterForXml.WriteLine("")

Else
StreamWriterForXml.Write("<" & currentTreeNode.Text & ">")

End If

If currentTreeNode.GetNodeCount(True) > 0 Then
'this node has children to parse, recursively call this program
SaveScreenChangesToFile(currentTreeNode)
End If

End While

StreamWriterForXml.Write("")
StreamWriterForXml.WriteLine("")

End Sub



----------END code that reads the treeview into a file


-- modified at 10:32 Monday 24th April, 2006
Questionlogical Pin
Amit Agarrwal24-Apr-06 2:43
Amit Agarrwal24-Apr-06 2:43 
AnswerRe: logical Pin
Steve Pullan24-Apr-06 2:53
Steve Pullan24-Apr-06 2:53 
GeneralRe: logical Pin
Amit Agarrwal24-Apr-06 3:12
Amit Agarrwal24-Apr-06 3:12 
GeneralRe: logical Pin
Dave Kreskowiak24-Apr-06 6:27
mveDave Kreskowiak24-Apr-06 6:27 
AnswerRe: logical Pin
Mohammed Amine24-Apr-06 16:05
Mohammed Amine24-Apr-06 16:05 
Questionbusiness intelligence graphs VS 2005 Pin
KatliwaMax24-Apr-06 2:08
KatliwaMax24-Apr-06 2:08 
AnswerRe: business intelligence graphs VS 2005 Pin
Steve Pullan24-Apr-06 2:42
Steve Pullan24-Apr-06 2:42 
Questionhow to create the folder dynamically in vb.net? Pin
Ron.S24-Apr-06 2:03
Ron.S24-Apr-06 2:03 
AnswerRe: how to create the folder dynamically in vb.net? Pin
Robert Rohde24-Apr-06 2:14
Robert Rohde24-Apr-06 2:14 
GeneralRe: how to create the folder dynamically in vb.net? Pin
Ron.S24-Apr-06 19:37
Ron.S24-Apr-06 19:37 
QuestionHow to print listview in VB.NET(winform) Pin
godslayer124-Apr-06 2:02
godslayer124-Apr-06 2:02 
AnswerRe: How to print listview in VB.NET(winform) Pin
Duncan Edwards Jones24-Apr-06 6:23
professionalDuncan Edwards Jones24-Apr-06 6:23 
GeneralRe: How to print listview in VB.NET(winform) Pin
erickoronoh10kip23-Sep-11 7:47
erickoronoh10kip23-Sep-11 7:47 
Questionconecting as400 db2 to vb6.0 Pin
Khan.R24-Apr-06 1:59
Khan.R24-Apr-06 1:59 
AnswerRe: conecting as400 db2 to vb6.0 Pin
Steve Pullan24-Apr-06 2:47
Steve Pullan24-Apr-06 2:47 
QuestionStore an image on a form Pin
cld17924-Apr-06 1:40
cld17924-Apr-06 1:40 
AnswerRe: Store an image on a form Pin
Dave Kreskowiak24-Apr-06 6:23
mveDave Kreskowiak24-Apr-06 6:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.