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. C#
  4. VB6 to C# conversion SetIndex issue

VB6 to C# conversion SetIndex issue

Scheduled Pinned Locked Moved C#
helpcsharpdata-structures
6 Posts 3 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.
  • X Offline
    X Offline
    xtr33me
    wrote on last edited by
    #1

    I was wondering if anyone has run into this problem and gotten around it in any way. Currently I am performing a front end conversion from a VB6 GUI to C#. It is quite a big change and therefore we are performing this in stages. Now in this process we currently are using "Microsoft.VisualBasic.Compatibility.VB6" array objects at times eg.RadioButtonArray, CheckBoxArray, etc. Now when using these, there is a "SetIndex" method that is used throughout the existing code and it seems that the designer does not like the idea of this method being called when EndInit has been called already. It essentially renders the designer useless and we get an error in the designer. What we currently do is in the "InitializeComponent" method we call only "BeginInit" on the various arrays, and then in the form constructor after "InitializeComponent" is called we have another method we created called "InitializeComponentArrays" which we call all methods needing to call "SetIndex" and then we call their "EndInit" methods. This allows designer to load everything fine until we make any adjustments to the designer. When this happens, the windows generated code inserts all the "EndInit" methods into the "InitializeComponent" method which causes the designer to crash, and I then need to go in and delete the lines that it has entered. It is quite annoying and I felt it was time to reach out and see if anyone else has any better resolutions. Thanks everyone! Dan

    L 1 Reply Last reply
    0
    • X xtr33me

      I was wondering if anyone has run into this problem and gotten around it in any way. Currently I am performing a front end conversion from a VB6 GUI to C#. It is quite a big change and therefore we are performing this in stages. Now in this process we currently are using "Microsoft.VisualBasic.Compatibility.VB6" array objects at times eg.RadioButtonArray, CheckBoxArray, etc. Now when using these, there is a "SetIndex" method that is used throughout the existing code and it seems that the designer does not like the idea of this method being called when EndInit has been called already. It essentially renders the designer useless and we get an error in the designer. What we currently do is in the "InitializeComponent" method we call only "BeginInit" on the various arrays, and then in the form constructor after "InitializeComponent" is called we have another method we created called "InitializeComponentArrays" which we call all methods needing to call "SetIndex" and then we call their "EndInit" methods. This allows designer to load everything fine until we make any adjustments to the designer. When this happens, the windows generated code inserts all the "EndInit" methods into the "InitializeComponent" method which causes the designer to crash, and I then need to go in and delete the lines that it has entered. It is quite annoying and I felt it was time to reach out and see if anyone else has any better resolutions. Thanks everyone! Dan

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

      Two suggestions: 1. don't touch the code inside InitializeComponent(), it isn't your code, it is the Designer's. And the Designer will change it any time it feels like changing it. 2. forget about SetIndex. If you need to easily access one or all of your checkboxes (or any other type of Control), create a collection yourself, by storing the references into a List<CheckBox> or something similar after your constructor called InitializeComponent(). A list accepts an integer index, so you can easily access the n-th checkbox if that is what you need. Alternatively you can enumerate all top-level Controls of a Form, and pick the one(s) you need, like so:

      foreach(Control c in this.Controls) {
      CheckBox cb=c as CheckBox;
      if (cb!=null) {
      // now cb points to one of your checkboxes
      }
      }

      :)

      Luc Pattyn


      Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.


      Local announcement (Antwerp region): Lange Wapper? Neen!


      N 1 Reply Last reply
      0
      • L Luc Pattyn

        Two suggestions: 1. don't touch the code inside InitializeComponent(), it isn't your code, it is the Designer's. And the Designer will change it any time it feels like changing it. 2. forget about SetIndex. If you need to easily access one or all of your checkboxes (or any other type of Control), create a collection yourself, by storing the references into a List<CheckBox> or something similar after your constructor called InitializeComponent(). A list accepts an integer index, so you can easily access the n-th checkbox if that is what you need. Alternatively you can enumerate all top-level Controls of a Form, and pick the one(s) you need, like so:

        foreach(Control c in this.Controls) {
        CheckBox cb=c as CheckBox;
        if (cb!=null) {
        // now cb points to one of your checkboxes
        }
        }

        :)

        Luc Pattyn


        Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.


        Local announcement (Antwerp region): Lange Wapper? Neen!


        N Offline
        N Offline
        N a v a n e e t h
        wrote on last edited by
        #3

        Luc Pattyn wrote:

        foreach(Control c in this.Controls) { CheckBox cb=c as CheckBox; if (cb!=null) { // now cb points to one of your checkboxes } }

        This is where you can have the luxury of LINQ. How about

        foreach (CheckBox checkbox in from Control c in this.Controls
        where c.GetType() == typeof(CheckBox)
        select c as CheckBox)
        {
        }

        :)

        Navaneeth How to use google | Ask smart questions

        modified on Thursday, September 17, 2009 11:43 AM

        L 1 Reply Last reply
        0
        • N N a v a n e e t h

          Luc Pattyn wrote:

          foreach(Control c in this.Controls) { CheckBox cb=c as CheckBox; if (cb!=null) { // now cb points to one of your checkboxes } }

          This is where you can have the luxury of LINQ. How about

          foreach (CheckBox checkbox in from Control c in this.Controls
          where c.GetType() == typeof(CheckBox)
          select c as CheckBox)
          {
          }

          :)

          Navaneeth How to use google | Ask smart questions

          modified on Thursday, September 17, 2009 11:43 AM

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

          This may all be true and beautiful, but it is not what the OP needs; he is struggling with old VB code and fiddling with InitializeComponent(), so lets stick to the essentials and postpone the unnecessary magic. BTW: I don't think your and my code are equivalent, mine also matches CheckBox derivatives. :)

          Luc Pattyn


          Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.


          Local announcement (Antwerp region): Lange Wapper? Neen!


          X N 2 Replies Last reply
          0
          • L Luc Pattyn

            This may all be true and beautiful, but it is not what the OP needs; he is struggling with old VB code and fiddling with InitializeComponent(), so lets stick to the essentials and postpone the unnecessary magic. BTW: I don't think your and my code are equivalent, mine also matches CheckBox derivatives. :)

            Luc Pattyn


            Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.


            Local announcement (Antwerp region): Lange Wapper? Neen!


            X Offline
            X Offline
            xtr33me
            wrote on last edited by
            #5

            Thanks for the help! Our code is not the same Luc, but I see what you were trying to do so I am going to play with that. I can't thank you enough for the quick response! Thanks again! Dan

            1 Reply Last reply
            0
            • L Luc Pattyn

              This may all be true and beautiful, but it is not what the OP needs; he is struggling with old VB code and fiddling with InitializeComponent(), so lets stick to the essentials and postpone the unnecessary magic. BTW: I don't think your and my code are equivalent, mine also matches CheckBox derivatives. :)

              Luc Pattyn


              Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.


              Local announcement (Antwerp region): Lange Wapper? Neen!


              N Offline
              N Offline
              N a v a n e e t h
              wrote on last edited by
              #6

              My mistake. It should be CheckBox. Updated the post. :)

              Navaneeth How to use google | Ask smart questions

              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