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. Exception:System.IndexOutOfRangeException (Urgent)

Exception:System.IndexOutOfRangeException (Urgent)

Scheduled Pinned Locked Moved C#
databasedata-structurestutorial
20 Posts 5 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.
  • S Saira Tanwir

    sorry about that i copied the incorrect code. the for loop looks like this int count=4; int[] indice = new int[count]; for(int i=0;i<count;i++) { indice[i] = TableListBox.CheckedIndices[i]; } return indice; TableList Box is a CheckedListBox. what this loop does is takes the item on the selected index of the list box and stores it in another array.

    C Offline
    C Offline
    chravisankar
    wrote on last edited by
    #5

    check the size of TableListBox.it should not be greater than count

    S 1 Reply Last reply
    0
    • C chravisankar

      check the size of TableListBox.it should not be greater than count

      S Offline
      S Offline
      Saira Tanwir
      wrote on last edited by
      #6

      the size property of the listbox just gives its width and height. what has that got to do with the exception??

      C 1 Reply Last reply
      0
      • S Saira Tanwir

        the size property of the listbox just gives its width and height. what has that got to do with the exception??

        C Offline
        C Offline
        chravisankar
        wrote on last edited by
        #7

        i am not talking about the physical size. i am talking about the count. check during run time.just place a brek point in the for loop and see whether TableList[i] is not greater than TableList[count]. right??

        1 Reply Last reply
        0
        • S Saira Tanwir

          sorry about that i copied the incorrect code. the for loop looks like this int count=4; int[] indice = new int[count]; for(int i=0;i<count;i++) { indice[i] = TableListBox.CheckedIndices[i]; } return indice; TableList Box is a CheckedListBox. what this loop does is takes the item on the selected index of the list box and stores it in another array.

          Q Offline
          Q Offline
          quiteSmart
          wrote on last edited by
          #8

          I believe that your error is that there is less than 4 checked items in the Table listBox so when the compiler tries to go to (for example) index 4 it is not found and it is out of range. try knowing how many items are checked before you initialize the other array and u do the for loop. you can do this int count = TableListBox.CheckedIndices.Count; and continue the rest of your code

          S 1 Reply Last reply
          0
          • Q quiteSmart

            I believe that your error is that there is less than 4 checked items in the Table listBox so when the compiler tries to go to (for example) index 4 it is not found and it is out of range. try knowing how many items are checked before you initialize the other array and u do the for loop. you can do this int count = TableListBox.CheckedIndices.Count; and continue the rest of your code

            S Offline
            S Offline
            Saira Tanwir
            wrote on last edited by
            #9

            i've already checked that the number of items selected in the listbox are 4 through int count=TableListBox.CheckedIndices.Count; approach. but still it doesn't work. Any other suggestions???

            Q C 2 Replies Last reply
            0
            • Q quiteSmart

              int count=4; int[] indice = new int[count]; MessageBox.Show(count.ToString()); for(int i=0;i indice[i] = TableListBox.CheckedIndices[i];<--Exception return indice; this is not C# coding

              J Offline
              J Offline
              J4amieC
              wrote on last edited by
              #10

              Why do you say that. (NB. the forum cut off everything after "for(int i=0;i" the line should have read "for(int i=0;i<count;i++)")

              --- How to get answers to your questions[^]

              Q 1 Reply Last reply
              0
              • J J4amieC

                Why do you say that. (NB. the forum cut off everything after "for(int i=0;i" the line should have read "for(int i=0;i<count;i++)")

                --- How to get answers to your questions[^]

                Q Offline
                Q Offline
                quiteSmart
                wrote on last edited by
                #11

                It is a good notice from you X| But i didn't know that the forum cut that out. Why don't u try to help that poor guy instead of loosing your time on unrelavent comments

                1 Reply Last reply
                0
                • S Saira Tanwir

                  i've already checked that the number of items selected in the listbox are 4 through int count=TableListBox.CheckedIndices.Count; approach. but still it doesn't work. Any other suggestions???

                  Q Offline
                  Q Offline
                  quiteSmart
                  wrote on last edited by
                  #12

                  Sorry, i cann't see any error in the code you are providing. Try providing us more information and maybe we can help

                  S 1 Reply Last reply
                  0
                  • Q quiteSmart

                    Sorry, i cann't see any error in the code you are providing. Try providing us more information and maybe we can help

                    S Offline
                    S Offline
                    Saira Tanwir
                    wrote on last edited by
                    #13

                    can this be due to the .Net Platform being corrupt? i'm really confused:confused::~

                    Q C 2 Replies Last reply
                    0
                    • S Saira Tanwir

                      can this be due to the .Net Platform being corrupt? i'm really confused:confused::~

                      Q Offline
                      Q Offline
                      quiteSmart
                      wrote on last edited by
                      #14

                      Is it the first time you develop on this Platform?

                      1 Reply Last reply
                      0
                      • S Saira Tanwir

                        can this be due to the .Net Platform being corrupt? i'm really confused:confused::~

                        C Offline
                        C Offline
                        Christian Graus
                        wrote on last edited by
                        #15

                        The odds of that are close to zero.

                        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                        S 1 Reply Last reply
                        0
                        • S Saira Tanwir

                          hi friends can anyone plz guide me on the exception An unhandled exception of type 'System.IndexOutOfRangeException' occurred in system.windows.forms.dll Additional information: Index was outside the bounds of the array. heres the code that gives me the exception int count=4; int[] indice = new int[count]; MessageBox.Show(count.ToString()); for(int i=0;i<--Exception return indice; plz reply quickly

                          C Offline
                          C Offline
                          Christian Graus
                          wrote on last edited by
                          #16

                          Saira Tanwir wrote:

                          plz reply quickly

                          This really bugs me. You're getting help for free, people will reply when they reply. No-one is 'on duty' int count=4; int[] indice = new int[count]; MessageBox.Show(count.ToString()); for(int i=0;i

                          S 1 Reply Last reply
                          0
                          • C Christian Graus

                            The odds of that are close to zero.

                            Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                            S Offline
                            S Offline
                            Saira Tanwir
                            wrote on last edited by
                            #17

                            thankyou for clearing that up and YES this is my first project on this platform

                            1 Reply Last reply
                            0
                            • C Christian Graus

                              Saira Tanwir wrote:

                              plz reply quickly

                              This really bugs me. You're getting help for free, people will reply when they reply. No-one is 'on duty' int count=4; int[] indice = new int[count]; MessageBox.Show(count.ToString()); for(int i=0;i

                              S Offline
                              S Offline
                              Saira Tanwir
                              wrote on last edited by
                              #18

                              well guys the problem is still there:^) But thanks anyway for all thee help and ur precious time regards:rose: Saira

                              C 1 Reply Last reply
                              0
                              • S Saira Tanwir

                                well guys the problem is still there:^) But thanks anyway for all thee help and ur precious time regards:rose: Saira

                                C Offline
                                C Offline
                                Christian Graus
                                wrote on last edited by
                                #19

                                Well, it's a really simple one. You need to step through the code and see what's happening, if you need to do that, to be convinced that hard coding the number 4 when the list could have less items is a bad idea. You'll see that it blows up because there are not four items checked. Nothing else makes sense.

                                Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                                1 Reply Last reply
                                0
                                • S Saira Tanwir

                                  i've already checked that the number of items selected in the listbox are 4 through int count=TableListBox.CheckedIndices.Count; approach. but still it doesn't work. Any other suggestions???

                                  C Offline
                                  C Offline
                                  chravisankar
                                  wrote on last edited by
                                  #20

                                  paste the full code i will test and let u know

                                  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