Click here to Skip to main content
15,888,351 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Don't tell me how to declare a string! Pin
joebeam10-Aug-07 9:00
joebeam10-Aug-07 9:00 
GeneralRe: Don't tell me how to declare a string! Pin
KarstenK6-Aug-07 4:41
mveKarstenK6-Aug-07 4:41 
GeneralRe: Don't tell me how to declare a string! Pin
Vasudevan Deepak Kumar6-Aug-07 5:10
Vasudevan Deepak Kumar6-Aug-07 5:10 
GeneralRe: Don't tell me how to declare a string! Pin
Chris Losinger6-Aug-07 15:31
professionalChris Losinger6-Aug-07 15:31 
GeneralRe: Don't tell me how to declare a string! Pin
LFirth21-Aug-07 5:22
LFirth21-Aug-07 5:22 
GeneralRe: Don't tell me how to declare a string! Pin
KarstenK6-Aug-07 20:25
mveKarstenK6-Aug-07 20:25 
GeneralRe: Don't tell me how to declare a string! Pin
Adam Maras9-Aug-07 5:47
Adam Maras9-Aug-07 5:47 
GeneralHave I gone completely mad? [modified] Pin
Robert Royall31-Jul-07 10:05
Robert Royall31-Jul-07 10:05 
Wait... don't answer that.

So at work I'm doing up a quick and dirty ASP.NET application that uses a TreeView. I'm still a bit of a beginner to programming for the web so I've been through the installed MSDN docs quite a bit for the past couple of weeks but I just ran across something that utterly blew my mind.

Anybody who has worked with TreeView knows it's got a few quirks, namely dealing with the fact that it's biased towards hierarchical data (why else would you use it?). I haven't had a lot of experience using .NET collections for a lot of things so combine that fact with the fun hierarchical nature of TreeView nodes and I have a lot of help doc reading to catch up on.

So I'm trying to find some sort of way to get at a TreeNodeCollection index without having to loop through an IEnumerator like so:
'enumerate through the nodes on this level and find out what the currently selected
'node's index is
Dim nodeEnumerator As IEnumerator
If selectedNode.Parent Is Nothing Then
    nodeEnumerator = trvTasks.Nodes.GetEnumerator
Else
    nodeEnumerator = selectedNode.Parent.ChildNodes.GetEnumerator
End If

'Counter code goes here

I'm hitting random members and I happen to land on the RemoveAt page. No big deal, right? There's no good information here on finding an index or anything...

Whiskey.
Tango.
Foxtrot.
OMG | :OMG:

From the integrated VS2005 help:
C++
void button2_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
{
   // Delete the first TreeNode in the collection
   // if the Text property is S"Node0."
   if ( this->treeView1->Nodes[ 0 ]->Text->Equals( "Node0" ) )
   {
      this->treeView1->Nodes->RemoveAt( 0 );
   }
}

Now I've dabbled in C++, and I've even done a little MFC in school, but is this really what you have to do in Managed C++? If C# is supposed to be all the best things about C++ then this looks like all the worst... No wonder nobody wants to touch the stuff.
GeneralRe: Have I gone completely mad? Pin
PIEBALDconsult31-Jul-07 10:30
mvePIEBALDconsult31-Jul-07 10:30 
GeneralRe: Have I gone completely mad? Pin
Robert Royall31-Jul-07 13:28
Robert Royall31-Jul-07 13:28 
GeneralRe: Have I gone completely mad? Pin
Andy Brummer31-Jul-07 18:57
sitebuilderAndy Brummer31-Jul-07 18:57 
GeneralRe: Have I gone completely mad? Pin
Haroon Sarwar31-Jul-07 22:12
Haroon Sarwar31-Jul-07 22:12 
GeneralRe: Have I gone completely mad? Pin
BadKarma31-Jul-07 22:29
BadKarma31-Jul-07 22:29 
GeneralRe: Have I gone completely mad? Pin
Brady Kelly31-Jul-07 23:46
Brady Kelly31-Jul-07 23:46 
GeneralRe: Have I gone completely mad? Pin
BadKarma31-Jul-07 23:53
BadKarma31-Jul-07 23:53 
GeneralRe: Have I gone completely mad? Pin
Robert Royall1-Aug-07 4:56
Robert Royall1-Aug-07 4:56 
GeneralRe: Have I gone completely mad? Pin
Andy Brummer31-Jul-07 19:00
sitebuilderAndy Brummer31-Jul-07 19:00 
GeneralRe: Have I gone completely mad? Pin
Robert Royall1-Aug-07 5:00
Robert Royall1-Aug-07 5:00 
GeneralRe: Have I gone completely mad? Pin
Andy Brummer1-Aug-07 5:10
sitebuilderAndy Brummer1-Aug-07 5:10 
GeneralRe: Have I gone completely mad? Pin
Robert Royall1-Aug-07 5:26
Robert Royall1-Aug-07 5:26 
GeneralRe: Have I gone completely mad? Pin
Andy Brummer1-Aug-07 5:31
sitebuilderAndy Brummer1-Aug-07 5:31 
JokeRe: Have I gone completely mad? Pin
Robert Royall1-Aug-07 5:38
Robert Royall1-Aug-07 5:38 
GeneralRe: Have I gone completely mad? Pin
Rob Achmann24-Aug-07 3:34
Rob Achmann24-Aug-07 3:34 
GeneralRe: Have I gone completely mad? Pin
Robert Royall24-Aug-07 12:25
Robert Royall24-Aug-07 12:25 
GeneralSoftware Pin
egionare31-Jul-07 6:54
egionare31-Jul-07 6:54 

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.