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. Visual Basic
  4. DataGridView - Why doesn't this work?

DataGridView - Why doesn't this work?

Scheduled Pinned Locked Moved Visual Basic
helpcssdatabasequestionannouncement
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.
  • P Offline
    P Offline
    penguin5000
    wrote on last edited by
    #1

    Hi, I'm trying to update the values in a DataGridView. It works ok, and I can see my rows and columns being updated, but when I scroll down the grid, and hit the bottom, it throws an "object not set to an instance of an object" error - and the space occupied by the grid changes to a red cross. I'm obviously doing something wrong, and have narrowed the problem down to this bit of code: Dim gridrow As DataRowView Dim intItemFoundOnRow As Integer = bindingDataGridView2.Find("File Name", strSearch) If intItemFoundOnRow <> -1 Then gridrow = bindingDataGridView2.Item(intItemFoundOnRow) gridrow.BeginEdit() gridrow.Item("Columns in Database") = CountColumnsInTable(strTableName) gridrow.EndEdit() End If It isn't anything to do with the CountColumnsInTable function, because I can replace this line with: gridrow.Item("Columns in Database") = 9999 ... and it makes no difference. I threw in .BeginEdit and .EndEdit in an attempt to get it to work, but these lines may as well not be there.

    G 1 Reply Last reply
    0
    • P penguin5000

      Hi, I'm trying to update the values in a DataGridView. It works ok, and I can see my rows and columns being updated, but when I scroll down the grid, and hit the bottom, it throws an "object not set to an instance of an object" error - and the space occupied by the grid changes to a red cross. I'm obviously doing something wrong, and have narrowed the problem down to this bit of code: Dim gridrow As DataRowView Dim intItemFoundOnRow As Integer = bindingDataGridView2.Find("File Name", strSearch) If intItemFoundOnRow <> -1 Then gridrow = bindingDataGridView2.Item(intItemFoundOnRow) gridrow.BeginEdit() gridrow.Item("Columns in Database") = CountColumnsInTable(strTableName) gridrow.EndEdit() End If It isn't anything to do with the CountColumnsInTable function, because I can replace this line with: gridrow.Item("Columns in Database") = 9999 ... and it makes no difference. I threw in .BeginEdit and .EndEdit in an attempt to get it to work, but these lines may as well not be there.

      G Offline
      G Offline
      GuyThiebaut
      wrote on last edited by
      #2

      Just an idea - is there any chance that you are trying to read past the end of the object bound to the datagrid. In some cases the first record in an object is 1 and in some cases it is 0 (I can't remember what is is in the case of a datagrid) I could be way off track here.

      You always pass failure on the way to success.

      P 1 Reply Last reply
      0
      • G GuyThiebaut

        Just an idea - is there any chance that you are trying to read past the end of the object bound to the datagrid. In some cases the first record in an object is 1 and in some cases it is 0 (I can't remember what is is in the case of a datagrid) I could be way off track here.

        You always pass failure on the way to success.

        P Offline
        P Offline
        penguin5000
        wrote on last edited by
        #3

        Thanks for your thoughts. I managed to fix it. The problem was that I had created a sorted DataView, and populated the DataGridView with it - which had the effect of sorting one of the columns, which seemed to have messed up the indexing. One thing I can't get my head around is that the grid was bound to the dataview, so the indices should, I think, have worked - irrespective of the sort.

        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