Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Have I gone completely mad? [modified]

Have I gone completely mad? [modified]

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharpc++asp-netdatabasehelp
17 Posts 7 Posters 7 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Robert Royall

    Well, when I was learning C++, ^ meant to the power of, /* */ meant some sort of comment, and -> meant accessing something through a pointer. From that stance, the method signature above contains an Object and an EventArgs to the power of... something, as well as two parameters that are essentially comments. Also, the first executable line tells me that you're going through the this pointer to hit the treeView1 pointer, which hits the Nodes pointer, which dereferences to the Text property, which somehow is also a pointer and must be dereferenced to hit the Equals method. Am I missing something or shouldn't there be a dot or two in there somewhere? As for the index, I need to know where my selected node is so I can insert nodes before and after it. TreeNodeCollection does give me an AddAt method that takes an integer index parameter... but the collection doesn't give me any way to access a node's index.

    H Offline
    H Offline
    Haroon Sarwar
    wrote on last edited by
    #6

    Robert Royall wrote:

    when I was learning C++, ^ meant to the power of

    in C++ ^ is the XOR operator, not power of operator... though i have no idea what its supposed to be doing there in the function you posted :|

    1 Reply Last reply
    0
    • R Robert Royall

      Well, when I was learning C++, ^ meant to the power of, /* */ meant some sort of comment, and -> meant accessing something through a pointer. From that stance, the method signature above contains an Object and an EventArgs to the power of... something, as well as two parameters that are essentially comments. Also, the first executable line tells me that you're going through the this pointer to hit the treeView1 pointer, which hits the Nodes pointer, which dereferences to the Text property, which somehow is also a pointer and must be dereferenced to hit the Equals method. Am I missing something or shouldn't there be a dot or two in there somewhere? As for the index, I need to know where my selected node is so I can insert nodes before and after it. TreeNodeCollection does give me an AddAt method that takes an integer index parameter... but the collection doesn't give me any way to access a node's index.

      B Offline
      B Offline
      BadKarma
      wrote on last edited by
      #7

      May I ask you where you learned c++, since to my recollection the ^ symbol was never user as power of but was and is used as an BIT wise Exclusive OR. In Managed C++ however the ^ is also used as pointer to managed objects 'newed' with gcnew instead of new.

      codito ergo sum

      B R 2 Replies Last reply
      0
      • B BadKarma

        May I ask you where you learned c++, since to my recollection the ^ symbol was never user as power of but was and is used as an BIT wise Exclusive OR. In Managed C++ however the ^ is also used as pointer to managed objects 'newed' with gcnew instead of new.

        codito ergo sum

        B Offline
        B Offline
        Brady Kelly
        wrote on last edited by
        #8

        Wow, I had completely forgotten that from my one year varsity of C++ back in '96. I still don;t remember the power operator.

        B 1 Reply Last reply
        0
        • B Brady Kelly

          Wow, I had completely forgotten that from my one year varsity of C++ back in '96. I still don;t remember the power operator.

          B Offline
          B Offline
          BadKarma
          wrote on last edited by
          #9

          C++ doens't have a power operator it has a power function double pow(double x, double y ); see MSDN[^]

          codito ergo sum

          1 Reply Last reply
          0
          • B BadKarma

            May I ask you where you learned c++, since to my recollection the ^ symbol was never user as power of but was and is used as an BIT wise Exclusive OR. In Managed C++ however the ^ is also used as pointer to managed objects 'newed' with gcnew instead of new.

            codito ergo sum

            R Offline
            R Offline
            Robert Royall
            wrote on last edited by
            #10

            Sorry, you are correct, ^ is XOR in C++. I got it mixed up with my VB syntax, which uses ^ as the power operator.

            1 Reply Last reply
            0
            • A Andy Brummer

              Why are you using an IEnumerator variable in your VB sample? Can't you use a NodeCollection variable and do a foreach loop instead?


              This blanket smells like ham

              R Offline
              R Offline
              Robert Royall
              wrote on last edited by
              #11

              I could have used foreach instead, but I wanted my code to reflect the fact that I was enumerating the collection only to count it. I tend to think of using foreach as "I'm doing something to each of these items in the collection", so I thought I'd use IEnumerator to specifically call out to myself that I'm only walking the collection and not making any edits.

              A 1 Reply Last reply
              0
              • R Robert Royall

                I could have used foreach instead, but I wanted my code to reflect the fact that I was enumerating the collection only to count it. I tend to think of using foreach as "I'm doing something to each of these items in the collection", so I thought I'd use IEnumerator to specifically call out to myself that I'm only walking the collection and not making any edits.

                A Offline
                A Offline
                Andy Brummer
                wrote on last edited by
                #12

                Interesting, I've never made that distinction before. I've had to avoid using foreach when I was modifying the collection (adding and removing elements), but for everything else I just use foreach. Personally I find the IEnumerator interface rather ugly and suspect it was designed to be hidden under the covers, so I'm content to leave it there. I definitely respect any conventions that make code easier to follow and understand though.


                This blanket smells like ham

                R 1 Reply Last reply
                0
                • A Andy Brummer

                  Interesting, I've never made that distinction before. I've had to avoid using foreach when I was modifying the collection (adding and removing elements), but for everything else I just use foreach. Personally I find the IEnumerator interface rather ugly and suspect it was designed to be hidden under the covers, so I'm content to leave it there. I definitely respect any conventions that make code easier to follow and understand though.


                  This blanket smells like ham

                  R Offline
                  R Offline
                  Robert Royall
                  wrote on last edited by
                  #13

                  It is eerily reminiscent of COM, isn't it? Just when you thought you were free from interface coclasses... :~ Actually, thinking on some of the comments in this topic, I ended up going back and rewriting it as a for loop this morning anyway, which let me keep the same counter variable and get rid of the IEnumerator.

                  A 1 Reply Last reply
                  0
                  • R Robert Royall

                    It is eerily reminiscent of COM, isn't it? Just when you thought you were free from interface coclasses... :~ Actually, thinking on some of the comments in this topic, I ended up going back and rewriting it as a for loop this morning anyway, which let me keep the same counter variable and get rid of the IEnumerator.

                    A Offline
                    A Offline
                    Andy Brummer
                    wrote on last edited by
                    #14

                    At one point in my life IDL actually started to make sense to me. X| :wtf:


                    This blanket smells like ham

                    R 1 Reply Last reply
                    0
                    • A Andy Brummer

                      At one point in my life IDL actually started to make sense to me. X| :wtf:


                      This blanket smells like ham

                      R Offline
                      R Offline
                      Robert Royall
                      wrote on last edited by
                      #15

                      I'm very sorry and I hope you can find the help you need. :doh:

                      1 Reply Last reply
                      0
                      • R Robert Royall

                        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: 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.

                        R Offline
                        R Offline
                        Rob Achmann
                        wrote on last edited by
                        #16

                        Were you just trying to delete the treeview thingy you clicked on via index? try this: Private Sub TreeView1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TreeView1.MouseUp me.TreeView1.Controls.RemoveAt( me.TreeView1.Controls.GetChildIndex(me.TreeView1.GetChildAtPoint(new Drawing.Point(e.x,e.Y))) End Sub

                        GaltSalt maker of .Net thingys

                        R 1 Reply Last reply
                        0
                        • R Rob Achmann

                          Were you just trying to delete the treeview thingy you clicked on via index? try this: Private Sub TreeView1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TreeView1.MouseUp me.TreeView1.Controls.RemoveAt( me.TreeView1.Controls.GetChildIndex(me.TreeView1.GetChildAtPoint(new Drawing.Point(e.x,e.Y))) End Sub

                          GaltSalt maker of .Net thingys

                          R Offline
                          R Offline
                          Robert Royall
                          wrote on last edited by
                          #17

                          No, actually I was just trying to access a node's index in the TreeNodeCollection in order to be able to insert another node before or after it in the collection. I just noticed the somewhat incomprehensible code in the Managed C++ section of the MSDN help for that method while I was browsing around.

                          Please don't bother me... I'm hacking code right now. Doesn't anybody remember what "hacking" really means? :sigh:

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups