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. Datagridview Error

Datagridview Error

Scheduled Pinned Locked Moved C#
cssdatabasehelpquestion
10 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.
  • K Offline
    K Offline
    kruegersck
    wrote on last edited by
    #1

    I have a datagridview bound to a datatable. When I remove a row from the datatable the grid reflects the change, but when I attempted to add a row back in I get an error System Index out of Range? I have tried datagridview1.Refresh() with no luck. What am I missing? Thanks

    P D 2 Replies Last reply
    0
    • K kruegersck

      I have a datagridview bound to a datatable. When I remove a row from the datatable the grid reflects the change, but when I attempted to add a row back in I get an error System Index out of Range? I have tried datagridview1.Refresh() with no luck. What am I missing? Thanks

      P Offline
      P Offline
      padmanabhan N
      wrote on last edited by
      #2

      Instead of refresh you can try to rebind the grid after deleting. (or) if this is a wrong solution a code sample would help a lot to give clear solution.

      Padmanabhan My Articles: Articles[^] My latest Article: Word Automation[^]

      K 1 Reply Last reply
      0
      • P padmanabhan N

        Instead of refresh you can try to rebind the grid after deleting. (or) if this is a wrong solution a code sample would help a lot to give clear solution.

        Padmanabhan My Articles: Articles[^] My latest Article: Word Automation[^]

        K Offline
        K Offline
        kruegersck
        wrote on last edited by
        #3

        Is there an article or code sample showing rebinding? Here is my code: //Are there rows that need to be deleted? for (int x = 0; x < dsInvoice.Tables["Invoice"].Rows.Count; x++) { if (dsInvoice.Tables["Invoice"].Rows[x]["QTYORD"].ToString() == "0") { dsInvoice.Tables["Invoice"].Rows[x].Delete(); dataGridView1.Refresh(); } } Thanks for all your help

        P 1 Reply Last reply
        0
        • K kruegersck

          Is there an article or code sample showing rebinding? Here is my code: //Are there rows that need to be deleted? for (int x = 0; x < dsInvoice.Tables["Invoice"].Rows.Count; x++) { if (dsInvoice.Tables["Invoice"].Rows[x]["QTYORD"].ToString() == "0") { dsInvoice.Tables["Invoice"].Rows[x].Delete(); dataGridView1.Refresh(); } } Thanks for all your help

          P Offline
          P Offline
          padmanabhan N
          wrote on last edited by
          #4

          Here is the mistake, you are getting the value from the database but after that deleting temporary. This will not reflect in database. Check my articles Refer 1:Temporary Values in Grid[^] Refer 2:GridView all in one[^]

          Padmanabhan My Articles: Articles[^] My latest Article: Word Automation[^]

          K 1 Reply Last reply
          0
          • P padmanabhan N

            Here is the mistake, you are getting the value from the database but after that deleting temporary. This will not reflect in database. Check my articles Refer 1:Temporary Values in Grid[^] Refer 2:GridView all in one[^]

            Padmanabhan My Articles: Articles[^] My latest Article: Word Automation[^]

            K Offline
            K Offline
            kruegersck
            wrote on last edited by
            #5

            I don't understand please forgive me. I am new to Datagridview grids. After I remove the row from datatable what do I need to do next? I read through your articles, but I am confused??

            1 Reply Last reply
            0
            • K kruegersck

              I have a datagridview bound to a datatable. When I remove a row from the datatable the grid reflects the change, but when I attempted to add a row back in I get an error System Index out of Range? I have tried datagridview1.Refresh() with no luck. What am I missing? Thanks

              D Offline
              D Offline
              dan sh
              wrote on last edited by
              #6

              Can you show the code you are using add the row?

              K 1 Reply Last reply
              0
              • D dan sh

                Can you show the code you are using add the row?

                K Offline
                K Offline
                kruegersck
                wrote on last edited by
                #7

                I created a DataSource with a DataTable in it and added it through the wizzard when I added the Grid to my form. When a user enters 0 in the first cell I want to remove that row from the grid. I hope this helps Thanks!

                D 1 Reply Last reply
                0
                • K kruegersck

                  I created a DataSource with a DataTable in it and added it through the wizzard when I added the Grid to my form. When a user enters 0 in the first cell I want to remove that row from the grid. I hope this helps Thanks!

                  D Offline
                  D Offline
                  dan sh
                  wrote on last edited by
                  #8

                  How are you adding the row after deletion? Since you are getting IndexOutOfRange exception, you should check all the indexes you are using while adding the row.

                  K 1 Reply Last reply
                  0
                  • D dan sh

                    How are you adding the row after deletion? Since you are getting IndexOutOfRange exception, you should check all the indexes you are using while adding the row.

                    K Offline
                    K Offline
                    kruegersck
                    wrote on last edited by
                    #9

                    I am clicking on the first cell in the next available row when I receive the error. When I selected the datatable to use for the grid it created a binding source. When I try to execute the RemoveAt with the binding source it errors out. Is there an easier way to do this?

                    D 1 Reply Last reply
                    0
                    • K kruegersck

                      I am clicking on the first cell in the next available row when I receive the error. When I selected the datatable to use for the grid it created a binding source. When I try to execute the RemoveAt with the binding source it errors out. Is there an easier way to do this?

                      D Offline
                      D Offline
                      dan sh
                      wrote on last edited by
                      #10

                      I have never used a wizard for doing something like this. I had set the datasource through code and deleted the row using same code as yours. I added and new row as well and didn't received any error.

                      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