Posted: 10/19/2010 9:37:18 AM EDT
|
I've got several treenodes in a treeview, some with children some without. I have 'grammers block today and cannot for the life of me figure out why my "for each node as treenode in treenodeX.nodes" is only fetching the last child and not each child node. What gives? |
|
Quoted:
for each do what? .NET as in C#, VB ...? In VB ... no semicolons ... trying to solve a performance issue rsL2A = data.getRS("SELECT * FROM L2Advisors L2A " & _ "inner join BillingStatus BS on L2A.L2AdvisorID = BS.EntityID " & _ "and BS.EntityLevel = 'L2Advisor' " & _ "WHERE BS.BillingPeriod = '" & strBillingPeriod & "' " & _ "and BS.AdvanceFlag = " & Math.Abs(CInt(AdvanceFlag)) & " " & _ "order by AdvisorDisplayName") Do While Not rsL2A.EOF() tnL2A = tvRelationships.Nodes.Add(rsL2A("AdvisorDisplayName").Value, rsL2A("AdvisorDisplayName").Value, getImageIndex(rsL2A("BillingStatusCode").Value), getImageIndex(rsL2A("BillingStatusCode").Value)) tnL2A.Tag = "L2A-" & rsL2A("L2AdvisorID").Value rsAdv = data.getRS("SELECT * " & _ "FROM Advisors A INNER JOIN BillingStatus BS on A.AdvisorID = BS.EntityID and BS.EntityLevel = 'Advisor' " & _ "WHERE L2AdvisorID = " & rsL2A("L2AdvisorID").Value & " " & _ "and BS.BillingPeriod = '" & BillingPeriod & "' " & _ "and BS.AdvanceFlag = " & Math.Abs(CInt(AdvanceFlag)) & " " & _ "ORDER BY AdvisorDisplayName") Do While Not rsAdv.EOF() tnAdv = tnL2A.Nodes.Add(rsAdv("AdvisorDisplayName").Value, rsAdv("AdvisorDisplayName").Value, getImageIndex(rsAdv("BillingStatusCode").Value), getImageIndex(rsAdv("BillingStatusCode").Value)) tnAdv.Tag = "ADV-" & rsAdv("AdvisorID").Value rsRel = data.getRS("SELECT pg.PGroupID, pg.DisplayName, pg.advisorID, bs.BillingStatusCode " & _ "FROM PortfolioGroups PG Inner join BillingStatus BS on PG.PGroupID = BS.EntityID and BS.EntityLevel = 'PGroup' " & _ "where AdvisorID = " & rsAdv("AdvisorID").Value & " " & _ "and BS.BillingPeriod = '" & BillingPeriod & "' " & _ "and BS.AdvanceFlag = " & Math.Abs(CInt(AdvanceFlag)) & " ") Do While Not rsRel.EOF() tnRel = tnAdv.Nodes.Add(rsRel("DisplayName").Value, rsRel("DisplayName").Value, getImageIndex(rsRel("BillingStatusCode").Value), getImageIndex(rsRel("BillingStatusCode").Value)) tnRel.Tag = "REL-" & rsRel("PGroupID").Value rsPortfolio = data.getRS("SELECT p.PortfolioID, p.PGroupID, p.DisplayName, bs.BillingStatusCode " & _ "FROM Portfolios P INNER JOIN BillingStatus BS on P.PortfolioID = BS.EntityID and BS.EntityLevel = 'Portfolio' " & _ "WHERE PGROUPID = " & rsRel("PGroupID").Value & " " & _ "and BS.BillingPeriod = '" & BillingPeriod & "' " & _ "and BS.AdvanceFlag = " & Math.Abs(CInt(AdvanceFlag)) & " ") Do While Not rsPortfolio.EOF() tnPor = tnRel.Nodes.Add(rsPortfolio("DisplayName").Value, rsPortfolio("DisplayName").Value, getImageIndex(rsPortfolio("BillingStatusCode").Value), getImageIndex(rsPortfolio("BillingStatusCode").Value)) tnPor.Tag = "POR-" & rsPortfolio("PortfolioID").Value rsPortfolio.MoveNext() Loop rsPortfolio.Close() rsRel.MoveNext() Loop rsRel.Close() rsAdv.MoveNext() Loop rsAdv.Close() rsL2A.MoveNext() Loop ––- I am simply trying to do Dim nodeNames as String For Each node as TreeNode in tnAdv.Nodes nodeNames += node.Name Next Messagebox.Show(nodeNames) Instead of getting back a collection of nodes I am only getting the last index of tnAdv |
|
MSDN Help We use Infragistics controls, so I don't have any sample code using the standard MS Treeview. |
|
Sprinkle output statements of the tree's size throughout your code, verify that it's increasing as you expect it to.
Do a test manual output of some of the tree nodes as well, right before your for each loop. You can do these with the debugger if you know how. Are you sure that treenodeX is the root node? Seeing the actual code would be more useful, not just the "what I'm trying to do" paraphrasing and resectioning. Use code blocks in the arfcom post editor, they're the pound symbol icon next to the image button in the original editor, not sure where exactly they are in the new one. |
|
I solved this problem a different way, thanks for the help though. Traversing the tree by nodes was what I was trying to do but couldn't manage for whateveer reason. I decided to write one large query and recursively generate the treeview that way, and this was also the fastest way. Optimizing (somebody elses') code sucks. |
|
Quoted: Quoted: Write a recursive routine to traverse the tree. This is the other thing I'm unclear on, OP, what's the default traversal for the treeview? I've never used it. If you haven't specified one, that may be your problem. I realized after the fact that treeviews apparently have a key and tag that you can use to spill objects, but this is too much work and wouldn't have solved the performance issue as gracefully. |
|
do you do this for a living or is this for class or fun?
had a guy in my department used to code like that. when he submitted the stuff to production i would rewrite it without telling him or his boss. eventually he did some really stupid things in a db i was responsible for. he left for the breadlines soon after. i do a number of things. one of them is 2nd level support. when i have a problem with code and have to figure it out in the middle of the night because a customer is screaming and i have to format it first, it get a bit irate. formatting code (going beyond what the IDE you use does) can greatly increase your productivity and reduce your errors, because it allows you to see mistakes immediately. this is less of an issue than it once was because most systems will do some formatting for you, but still it can make you more productive if you go a bit beyond what the defaults are. i hate vb for the way it does continuation. it can be very powerful. big stuff in dotnet i write in c# because it allows a bit more c++ like formatting. |
|
Quoted:
Quoted:
Quoted:
Write a recursive routine to traverse the tree. This is the other thing I'm unclear on, OP, what's the default traversal for the treeview? I've never used it. If you haven't specified one, that may be your problem. I realized after the fact that treeviews apparently have a key and tag that you can use to spill objects, but this is too much work and wouldn't have solved the performance issue as gracefully. if performance is your issue is suggest you write it in win32, with an COM+ OLEDB access method to your db. Put as much of the stuff as you can in the db layer. |
|
Quoted: do you do this for a living or is this for class or fun? had a guy in my department used to code like that. when he submitted the stuff to production i would rewrite it without telling him or his boss. eventually he did some really stupid things in a db i was responsible for. he left for the breadlines soon after. i do a number of things. one of them is 2nd level support. when i have a problem with code and have to figure it out in the middle of the night because a customer is screaming and i have to format it first, it get a bit irate. formatting code (going beyond what the IDE you use does) can greatly increase your productivity and reduce your errors, because it allows you to see mistakes immediately. this is less of an issue than it once was because most systems will do some formatting for you, but still it can make you more productive if you go a bit beyond what the defaults are. i hate vb for the way it does continuation. it can be very powerful. big stuff in dotnet i write in c# because it allows a bit more c++ like formatting. This is a nagging side project for work, this is some old coding that somebody else did not know very much VB (and surprise they have another guy who isn't totally kosher with VB working on it). Problem 1 for me was that it is using legacy ADODB COM objects instead of new-fangled .NET. Problem 2 is the awkward continuation ... I'm personally using a string builder, like you said it is faster to develop and troubleshoot. |
|
Quoted: Quoted: Quoted: Quoted: Write a recursive routine to traverse the tree. This is the other thing I'm unclear on, OP, what's the default traversal for the treeview? I've never used it. If you haven't specified one, that may be your problem. I realized after the fact that treeviews apparently have a key and tag that you can use to spill objects, but this is too much work and wouldn't have solved the performance issue as gracefully. if performance is your issue is suggest you write it in win32, with an COM+ OLEDB access method to your db. Put as much of the stuff as you can in the db layer. You posted while I was posting, I'm definitely not using legacy ADO access anymore. ETA: But that is not the main issue, the main issue is/was nesting 4 loops and the 3rd and 4th order loops generating an exponential amount of results (to the tune of hundreds of millions). |
|
Quoted:
do you do this for a living or is this for class or fun? had a guy in my department used to code like that. when he submitted the stuff to production i would rewrite it without telling him or his boss. eventually he did some really stupid things in a db i was responsible for. he left for the breadlines soon after. i do a number of things. one of them is 2nd level support. when i have a problem with code and have to figure it out in the middle of the night because a customer is screaming and i have to format it first, it get a bit irate. formatting code (going beyond what the IDE you use does) can greatly increase your productivity and reduce your errors, because it allows you to see mistakes immediately. this is less of an issue than it once was because most systems will do some formatting for you, but still it can make you more productive if you go a bit beyond what the defaults are. i hate vb for the way it does continuation. it can be very powerful. big stuff in dotnet i write in c# because it allows a bit more c++ like formatting. big plus one on code formatting... I cant read what is going on here |
|
Quoted: Quoted: do you do this for a living or is this for class or fun? had a guy in my department used to code like that. when he submitted the stuff to production i would rewrite it without telling him or his boss. eventually he did some really stupid things in a db i was responsible for. he left for the breadlines soon after. i do a number of things. one of them is 2nd level support. when i have a problem with code and have to figure it out in the middle of the night because a customer is screaming and i have to format it first, it get a bit irate. formatting code (going beyond what the IDE you use does) can greatly increase your productivity and reduce your errors, because it allows you to see mistakes immediately. this is less of an issue than it once was because most systems will do some formatting for you, but still it can make you more productive if you go a bit beyond what the defaults are. i hate vb for the way it does continuation. it can be very powerful. big stuff in dotnet i write in c# because it allows a bit more c++ like formatting. big plus one on code formatting... I cant read what is going on here Code formatting wasn't what he was talking about ... it's the gay string concatenation in VB. |
If anyone cares ... I finally solved it! App runtime down from 30+ seconds to 1 and change.
Dim dt As New DataTable |
|
Needs more: LINQ (or at least stored procedure), DAL, SOA, C#
Good use of StringBuilder vs regular string concatenation but you should be able to instantiate the query string without doing any appending / concatenating anyway. In C# you can prepend the opening quotes of a string with @, for example:
In VB you have to use & _ at the end of each line for the same result:
Edit: Edited to add that I see that & _ was used in the original code. StringBuilder is extremely fast but & _ should be faster (the compiler is smart enough to group it all together as a single value rather than concating it –– this is handled at build time rather than run-time which is where StringBuilder would come into play). |
|
Quoted:
Needs more: LINQ (or at least stored procedure), DAL, SOA, C# Good use of StringBuilder vs regular string concatenation but you should be able to instantiate the query string without doing any appending / concatenating anyway. In C# you can prepend the opening quotes of a string with @, for example: var someString = @"thisiscompletelyvalid"; In VB you have to use & _ at the end of each line for the same result: someString = "this" & _ "is" & _ "valid " I hear you but I don't got a choice The older slower code was written with "& _" and I was not in love with it. |
I'm not a fan of VB.NET, but you can use XML literals for multiline strings:
Dim s As String = <a>SELECT * or Dim s As String = <a><
