Windows Develop Bookmark and Share   
 index > Windows Forms General > error 0 filling treeview control
 

error 0 filling treeview control

Using VS2005 with VB.NET, I am trying to populate a three level TreeView control.

The code belowsteps thru the rows ofa sql server 2005 table andgets data from three fields. Each field contains the text for each level. It works ok except that when it gets to the third level TableNameNode (in italics)it generates error number 0. Can anyone help resolve this?

Code Snippet

For Each IndicatorCategoryRow In TableReferenceTable.Rows

IndicatorCategoryNode = New TreeNode(IndicatorCategoryRow.Item("IndicatorCategory"))

If Not (tempIndicatorCategoryNodeText = IndicatorCategoryNode.Text) Then

tempIndicatorCategoryNodeText = IndicatorCategoryNode.Text

trvTblToRef.Nodes.Add(IndicatorCategoryNode)

End If

'start populate SchemaName

For Each SchemaNameRow In TableReferenceTable.Rows

SchemaNameNode = New TreeNode(SchemaNameRow.Item("SchemaName"))

If Not (SchemaNameNode.Text = tempSchemaNameNodeText) Then

If IndicatorCategoryNode.Text = SchemaNameRow.Item("IndicatorCategory") Then

tempSchemaNameNodeText = SchemaNameNode.Text

IndicatorCategoryNode.Nodes.Add(SchemaNameNode)

End If

End If

'start populate TableName

For Each TableNameRow In TableReferenceTable.Rows

TableNameNode = New TreeNode(TableNameRow.Item("TableName"))

If Not (TableNameNode.Text = tempTableNameNodeText) Then

If SchemaNameNode.Text = TableNameRow.Item("SchemaName") Then

tempTableNameNodeText = TableNameNode.Text

SchemaNameNode.Nodes.Add(TableNameNode)

End If

End If

Next TableNameRow

'end populate TableName

Next SchemaNameRow

'end populate SchemaName

Next IndicatorCategoryRow

'end populate ICategory

rwbogosian  Saturday, May 17, 2008 3:08 AM
Error 0? Don't you get an exception? A nice stack trace? One thing that jumps out is that you seem to assume that the rows in your DataTable are ordered just right so you can step through them and refer to their IndicatorCategory and SchemaName columns in the order you want them. That's not typically the way database queries work. They are "sets", not "arrays". You'd normally query to get the rows of SchemaNames, then for each SchemaName query to get a row of TableNames.

I see no obvious mistake in the way you create the treeview nodes. Check if you still get the same error without creating nodes.
nobugz  Saturday, May 17, 2008 1:10 PM

Just getting Error 0; no description.

Code very similar to this (contains one more nested node loop)worked without incident; it also accessed a DataTable. Each row in the table contains IndicatorCategory, SchemaName, TableName. The codeuses nested loops so it checks each row for matching data. The test was done ona table which contains only onerecord. During debugging I can see that the variables contain the correct data.

rwbogosian  Saturday, May 17, 2008 5:46 PM

You can use google to search for other answers

Custom Search

More Threads

• VS05 - System.Windows.Forms.PictureBox - Multiple Pictures in same box??
• how to move from Form to Form?
• Justifying Text
• construct mdi appear only once
• DataGridView NotifyCurrentCellDirty usage
• COMBOBOX VALIDATION
• PropertyGrid: Can toggle Readonly attribute, but not Visibility
• WinForm Class Library and AppUpdater component
• Grouping Menu Items on Drop Down Menu
• Can I Use Buttons To Change Pages?