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 null row

DataGridView null row

Scheduled Pinned Locked Moved C#
questioncss
3 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.
  • T Offline
    T Offline
    tjschilling
    wrote on last edited by
    #1

    I have a DataGridView that has a DataTable set as the data source. When I add a row to the DataTable, it does get added to the grid but it is followed by a null row that sits between the row I just added and the next new row. How do I prevent this bogus row from appearing on the data grid?

    E 1 Reply Last reply
    0
    • T tjschilling

      I have a DataGridView that has a DataTable set as the data source. When I add a row to the DataTable, it does get added to the grid but it is followed by a null row that sits between the row I just added and the next new row. How do I prevent this bogus row from appearing on the data grid?

      E Offline
      E Offline
      Ennis Ray Lynch Jr
      wrote on last edited by
      #2

      Often when there is a null row there is an error in the code that is adding rows to the DataTable. I would check that logic. If you would rather apply a hack than a fix to the error you can capture the Data Binding events for the DataGridView and manually remove the null records.

      Need a C# Consultant? I'm available.
      Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway

      T 1 Reply Last reply
      0
      • E Ennis Ray Lynch Jr

        Often when there is a null row there is an error in the code that is adding rows to the DataTable. I would check that logic. If you would rather apply a hack than a fix to the error you can capture the Data Binding events for the DataGridView and manually remove the null records.

        Need a C# Consultant? I'm available.
        Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway

        T Offline
        T Offline
        tjschilling
        wrote on last edited by
        #3

        You pointed in a good direction but I still don't know why this is happening. I checked the row added event on the grid and sure enough, when that is getting fired, there is an additional null row in my DataTable which is affecting the grid. When the new row in the DataTable gets committed, the null row disappears from the DataTable but the grid hangs on to it. I can't find any problems with the logic that adds the row to the DataTable so I decided to loop backwards through the grid and get rid of all rows in the DataGrid that do not exist in the DataTable.

        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