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. General Programming
  3. .NET (Core and Framework)
  4. Help Translating Code Snippet from C# to MC++

Help Translating Code Snippet from C# to MC++

Scheduled Pinned Locked Moved .NET (Core and Framework)
questioncsharpc++comtools
5 Posts 2 Posters 0 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 Offline
    R Offline
    ricecake
    wrote on last edited by
    #1

    Since nobody responded to my previous question[^], I did some more research and thought I'd try a different approach, but the solution I found was only given in C# and VB, and I do not know how to translate this to MC++ since MC++ doesn't have the foreach keyword. I want to try to implement the code given at http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q1008q[^]... the link won't take you directly to the question in Firefox, so it is question 5.87 (the same snippet is given on MSDN[^] but the navigation on that page is broken). Basically, I am using a DataGrid as a display-only control, so I don't want to be able to do any editing using the DataGrid. The above-cited question has the suggestion of removing all controls from the DataGrid (except for the scrollbars):

    ArrayList al = new ArrayList();
    foreach (Control c in this.dataGrid1.Controls) {
    if (c.GetType() == typeof(VScrollBar) || c.GetType() == typeof(HScrollBar)) {
    al.Add(c);
    }
    }
    this.dataGrid1.Controls.Clear();
    this.dataGrid1.Controls.AddRange((Control[]) al.ToArray(typeof(Control)));

    How do I translate this into Managed C++? Specifically, the foreach is tripping me up. I think I can implement the GetType/typeof stuff with __try_casts.

    -- Marcus Kwok

    L 1 Reply Last reply
    0
    • R ricecake

      Since nobody responded to my previous question[^], I did some more research and thought I'd try a different approach, but the solution I found was only given in C# and VB, and I do not know how to translate this to MC++ since MC++ doesn't have the foreach keyword. I want to try to implement the code given at http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q1008q[^]... the link won't take you directly to the question in Firefox, so it is question 5.87 (the same snippet is given on MSDN[^] but the navigation on that page is broken). Basically, I am using a DataGrid as a display-only control, so I don't want to be able to do any editing using the DataGrid. The above-cited question has the suggestion of removing all controls from the DataGrid (except for the scrollbars):

      ArrayList al = new ArrayList();
      foreach (Control c in this.dataGrid1.Controls) {
      if (c.GetType() == typeof(VScrollBar) || c.GetType() == typeof(HScrollBar)) {
      al.Add(c);
      }
      }
      this.dataGrid1.Controls.Clear();
      this.dataGrid1.Controls.AddRange((Control[]) al.ToArray(typeof(Control)));

      How do I translate this into Managed C++? Specifically, the foreach is tripping me up. I think I can implement the GetType/typeof stuff with __try_casts.

      -- Marcus Kwok

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      there is no magic involved in foreach; it expects a enumerable list of items of the correct type (it is not ignoring list elements that ar not of the type you want, they would throw!). So you can replace:

      foreach (Control c in Controls) {
      c.something();
      }

      by

      int n=Controls.Count;
      for (int i=0; i<n; i++) {
      Control c=Controls[i];
      c.something();
      }

      because in this case Controls is a Control array; you could generalize with the enumerator interface if necessary. :) -- modified at 10:21 Thursday 8th February, 2007

      Luc Pattyn

      R 1 Reply Last reply
      0
      • L Luc Pattyn

        there is no magic involved in foreach; it expects a enumerable list of items of the correct type (it is not ignoring list elements that ar not of the type you want, they would throw!). So you can replace:

        foreach (Control c in Controls) {
        c.something();
        }

        by

        int n=Controls.Count;
        for (int i=0; i<n; i++) {
        Control c=Controls[i];
        c.something();
        }

        because in this case Controls is a Control array; you could generalize with the enumerator interface if necessary. :) -- modified at 10:21 Thursday 8th February, 2007

        Luc Pattyn

        R Offline
        R Offline
        ricecake
        wrote on last edited by
        #3

        Thanks... I think your less-than sign got eaten by the HTML, but I think I got the idea. I'll give it a shot.

        -- Marcus Kwok

        L 1 Reply Last reply
        0
        • R ricecake

          Thanks... I think your less-than sign got eaten by the HTML, but I think I got the idea. I'll give it a shot.

          -- Marcus Kwok

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Sorry for that, I changed it so it doesnt get eaten anymore. :)

          Luc Pattyn

          R 1 Reply Last reply
          0
          • L Luc Pattyn

            Sorry for that, I changed it so it doesnt get eaten anymore. :)

            Luc Pattyn

            R Offline
            R Offline
            ricecake
            wrote on last edited by
            #5

            Thanks!

            -- Marcus Kwok

            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