
Inherits - TreeNode Control
Ryan,
Thanks for your solution, but I need little more help,
How can I make my class spkNode to return spkNode from the .Add
method, I want spkNode class to work as like TreeNode does,
My requirement here is that, I read the data from the database and
create the node with the 'Title' and store the 'ProgramName' &
'ProgramType' in properties, if it is a parent node, I need to add
child node to it and it goes on and on.
Please help me,
Thanks in advance,
Sudhakar
Quote:
> The problem (as indicated below) is that you're trying to "downcast" when
> that isn't valid. The return type from the .Add method is TreeNode, not
> spkNode, so casting in that direction isn't allowed. I think what you want
> do is this
> Class spkNode
> Inherits TreeNode
> Public Sub New(ByVal text As String)
> MyBase.New(text)
> End Sub
> End Class
> then when you want to use it...
> Dim myNode As New spkNode("Hello, world")
> TreeView1.Nodes.Add(myNode)
> For i As Integer = 0 To 6
> myNode = New spkNode("i = " & i)
> TreeView1.Nodes.Add(myNode)
> Next i
> This posting is provided "AS IS" with no warranties, and confers no rights.
> > Hai Everyone...
> > I having problem with the class derived from the TreeNode,
> > Class called spkNode
> > Inherits System.Windows.Forms.TreeNode
> > End Class
> > The following code does not work, I get System.InvalidCastException,
> > additional info : Specified Cast is not valid,
> > Dim objNode As New spkNode()
> the cast below here is not valid because the return type is not the same as
> the type of objNode
> > objNode = TreeView1.Nodes.Add("ssi")
> > Dim i As Integer
> > For i = 0 To 6
> > objNode.Text = "ssi = " & i
> > objNode = objNode.Nodes.Add(objNode.Text)
> > Next
> > but the same code with {*filter*}ode, work properly,
> > Dim objNode As New TreeNode()
> > objNode = TreeView1.Nodes.Add("ssi")
> > Dim i As Integer
> > For i = 0 To 6
> > objNode.Text = "ssi = " & i
> > objNode = objNode.Nodes.Add(objNode.Text)
> > Next
> > Am I missing some thing here, if my class works I need to add few
> > properties, any suggestions greatly appreciated.
> > Thanks in advance,
> > Sudhakar