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. Windows Forms
  4. Datagridview cell not updating in Windows 2008 SP2 server

Datagridview cell not updating in Windows 2008 SP2 server

Scheduled Pinned Locked Moved Windows Forms
sysadmin
17 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.
  • H harvid

    DataGridView1.Item("ApprovedDateTime", e.RowIndex).Value = Now() DataGridView1.Item("ApprovedBy", e.RowIndex).Value = Username But the same code works fine for below columns DataGridView1.Rows(e.RowIndex).Cells("LastModifiedBy").Value = Username DataGridView1.Rows(e.RowIndex).Cells("LastModifiedDateTime").Value = Now() I tried to mimic the Null reference error, by replacing the first two lines with the below lines DataGridView1.Item("ApprovedDateTime", e.RowIndex).Value = now() DataGridView1.Item("ApprovedBy", e.RowIndex).Value = username even now also, i'm experiencing same issue and Application got crashed.

    P Offline
    P Offline
    Pete OHanlon
    wrote on last edited by
    #6

    What are the column definitions for those fields (both the Approved... and the LastModified... fields)? If you could show us your table definitions then we could have a look.

    *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

    "Mind bleach! Send me mind bleach!" - Nagy Vilmos

    My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

    H 1 Reply Last reply
    0
    • P Pete OHanlon

      What are the column definitions for those fields (both the Approved... and the LastModified... fields)? If you could show us your table definitions then we could have a look.

      *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

      "Mind bleach! Send me mind bleach!" - Nagy Vilmos

      My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

      H Offline
      H Offline
      harvid
      wrote on last edited by
      #7

      Hello Pete, Pls find the details below. ColumnName DataType Length Nullable -------------------------------------------------------- ApprovedFlag int 4 no ApprovedDateTime datetime 8 yes ApprovedBy varchar 30 yes LastModifiedBy varchar 30 yes LastModifiedDateTime datetime 8 yes

      P 1 Reply Last reply
      0
      • H harvid

        Hello Pete, Pls find the details below. ColumnName DataType Length Nullable -------------------------------------------------------- ApprovedFlag int 4 no ApprovedDateTime datetime 8 yes ApprovedBy varchar 30 yes LastModifiedBy varchar 30 yes LastModifiedDateTime datetime 8 yes

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #8

        Hmmm. Sorry, I can't see what's happening. What you could do, is attach the query explorer to the SQL Server instance, and see what SQL it's receiving. That would be what I would do.

        *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

        "Mind bleach! Send me mind bleach!" - Nagy Vilmos

        My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

        H 1 Reply Last reply
        0
        • P Pete OHanlon

          Hmmm. Sorry, I can't see what's happening. What you could do, is attach the query explorer to the SQL Server instance, and see what SQL it's receiving. That would be what I would do.

          *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

          "Mind bleach! Send me mind bleach!" - Nagy Vilmos

          My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

          H Offline
          H Offline
          harvid
          wrote on last edited by
          #9

          Could you please let me know the steps to do this?

          P 1 Reply Last reply
          0
          • H harvid

            Could you please let me know the steps to do this?

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #10

            You can find out how to do this here[^].

            *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

            "Mind bleach! Send me mind bleach!" - Nagy Vilmos

            My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

            H 1 Reply Last reply
            0
            • P Pete OHanlon

              You can find out how to do this here[^].

              *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

              "Mind bleach! Send me mind bleach!" - Nagy Vilmos

              My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

              H Offline
              H Offline
              harvid
              wrote on last edited by
              #11

              Hello Pete, I tried to debug the code in the server after installing Visual studio. I'm getting the below error in Cell_formatting event in this line dgEditor.Rows(e.RowIndex).Cells("Status").Value = "Used" e.CellStyle.BackColor = Color.LightGreen e.CellStyle.SelectionBackColor = Color.LightGreen e.CellStyle.SelectionForeColor = Color.Black ERROR: An unhandled exception of type 'System.StackOverflowException' occurred in System.Windows.Forms.dll {Unable to evaluate expression.} I have made a check below, but it is partly working and not updating "Status" column and coloring, If e.Value Is Nothing Then Exit Sub End If Is there anyway i can mimic this issue? Please help. I can also paste my Cell_formating code if you want to look at it.

              P 1 Reply Last reply
              0
              • H harvid

                Hello Pete, I tried to debug the code in the server after installing Visual studio. I'm getting the below error in Cell_formatting event in this line dgEditor.Rows(e.RowIndex).Cells("Status").Value = "Used" e.CellStyle.BackColor = Color.LightGreen e.CellStyle.SelectionBackColor = Color.LightGreen e.CellStyle.SelectionForeColor = Color.Black ERROR: An unhandled exception of type 'System.StackOverflowException' occurred in System.Windows.Forms.dll {Unable to evaluate expression.} I have made a check below, but it is partly working and not updating "Status" column and coloring, If e.Value Is Nothing Then Exit Sub End If Is there anyway i can mimic this issue? Please help. I can also paste my Cell_formating code if you want to look at it.

                P Offline
                P Offline
                Pete OHanlon
                wrote on last edited by
                #12

                Wait a second. You're changing the value of some text here in this event? I'm pretty sure that will trigger the event again - this would lead to a StackOverflowException.

                *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

                "Mind bleach! Send me mind bleach!" - Nagy Vilmos

                My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

                H 1 Reply Last reply
                0
                • P Pete OHanlon

                  Wait a second. You're changing the value of some text here in this event? I'm pretty sure that will trigger the event again - this would lead to a StackOverflowException.

                  *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

                  "Mind bleach! Send me mind bleach!" - Nagy Vilmos

                  My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

                  H Offline
                  H Offline
                  harvid
                  wrote on last edited by
                  #13

                  Please let me know if there are any steps to overcome it.? I will need to set the Color for "status" column.

                  L 1 Reply Last reply
                  0
                  • H harvid

                    Please let me know if there are any steps to overcome it.? I will need to set the Color for "status" column.

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

                    When an event is called SomethingChanged, you expect it to fire only when Something gets a value different from the current one. However in WinForms some of those events will also fire when assigning the same value as the property already had, and that is one way to get StackOverflowException. The easiest way around is by explicitly testing yourself, as in:

                    ...
                    if (Something!=theValueIWant) Something=theValueIWant;
                    ...
                    

                    }

                    And yes, those events carry the wrong name, should have been GotAssignedTo or something such. :)

                    Luc Pattyn [My Articles] Nil Volentibus Arduum

                    H 1 Reply Last reply
                    0
                    • L Luc Pattyn

                      When an event is called SomethingChanged, you expect it to fire only when Something gets a value different from the current one. However in WinForms some of those events will also fire when assigning the same value as the property already had, and that is one way to get StackOverflowException. The easiest way around is by explicitly testing yourself, as in:

                      ...
                      if (Something!=theValueIWant) Something=theValueIWant;
                      ...
                      

                      }

                      And yes, those events carry the wrong name, should have been GotAssignedTo or something such. :)

                      Luc Pattyn [My Articles] Nil Volentibus Arduum

                      H Offline
                      H Offline
                      harvid
                      wrote on last edited by
                      #15

                      If dgEditor.Columns(e.ColumnIndex).Name = "Status" Then If dgEditor.Rows(e.RowIndex).Cells("Status").Value = "NEW" Then 'if already marked as new, leave it alone If IsDBNull(dgEditor.Rows(e.RowIndex).Cells("CommonLineName").Value) Then Else If dgEditor.Rows(e.RowIndex).Cells("CommonLineName").Value <> "" Then e.CellStyle.SelectionForeColor = Color.DarkGreen e.CellStyle.ForeColor = Color.DarkGreen e.CellStyle.BackColor = Color.Orange e.CellStyle.SelectionBackColor = Color.Orange End If End If Else If dgEditor.Rows(e.RowIndex).Cells("UsedFlag").Value = 1 Then dgEditor.Rows(e.RowIndex).Cells("Status").Value = "Used" e.CellStyle.BackColor = Color.LightGreen e.CellStyle.SelectionBackColor = Color.LightGreen e.CellStyle.SelectionForeColor = Color.Black Else If dgEditor.Rows(e.RowIndex).Cells("ExpiredFlag").Value = 1 Then If dgEditor.Rows(e.RowIndex).Cells("ApprovedFlag").Value = 1 Then dgEditor.Rows(e.RowIndex).Cells("Status").Value = "UnUsed" 'approved expired e.CellStyle.BackColor = Color.LightGray e.CellStyle.SelectionBackColor = Color.LightGray Else If dgEditor.Rows(e.RowIndex).Cells("RejectedFlag").Value = 1 Then dgEditor.Rows(e.RowIndex).Cells("Status").Value = "Expired" 'Rejected expired e.CellStyle.BackColor = Color.LightCoral e.CellStyle.SelectionBackColor = Color.LightCoral Else dgEditor.Rows(e.RowIndex).Cells("Status").Value = "Expired" 'pure expired - never approved and never rejected e.CellStyle.BackColor = Color.Gray e.CellStyle.SelectionBackColor = Color.Gray End If End If Else If dgEditor.Rows(e.RowIndex).Cells("RejectedFlag").Value = 1 Then

                      L 1 Reply Last reply
                      0
                      • H harvid

                        If dgEditor.Columns(e.ColumnIndex).Name = "Status" Then If dgEditor.Rows(e.RowIndex).Cells("Status").Value = "NEW" Then 'if already marked as new, leave it alone If IsDBNull(dgEditor.Rows(e.RowIndex).Cells("CommonLineName").Value) Then Else If dgEditor.Rows(e.RowIndex).Cells("CommonLineName").Value <> "" Then e.CellStyle.SelectionForeColor = Color.DarkGreen e.CellStyle.ForeColor = Color.DarkGreen e.CellStyle.BackColor = Color.Orange e.CellStyle.SelectionBackColor = Color.Orange End If End If Else If dgEditor.Rows(e.RowIndex).Cells("UsedFlag").Value = 1 Then dgEditor.Rows(e.RowIndex).Cells("Status").Value = "Used" e.CellStyle.BackColor = Color.LightGreen e.CellStyle.SelectionBackColor = Color.LightGreen e.CellStyle.SelectionForeColor = Color.Black Else If dgEditor.Rows(e.RowIndex).Cells("ExpiredFlag").Value = 1 Then If dgEditor.Rows(e.RowIndex).Cells("ApprovedFlag").Value = 1 Then dgEditor.Rows(e.RowIndex).Cells("Status").Value = "UnUsed" 'approved expired e.CellStyle.BackColor = Color.LightGray e.CellStyle.SelectionBackColor = Color.LightGray Else If dgEditor.Rows(e.RowIndex).Cells("RejectedFlag").Value = 1 Then dgEditor.Rows(e.RowIndex).Cells("Status").Value = "Expired" 'Rejected expired e.CellStyle.BackColor = Color.LightCoral e.CellStyle.SelectionBackColor = Color.LightCoral Else dgEditor.Rows(e.RowIndex).Cells("Status").Value = "Expired" 'pure expired - never approved and never rejected e.CellStyle.BackColor = Color.Gray e.CellStyle.SelectionBackColor = Color.Gray End If End If Else If dgEditor.Rows(e.RowIndex).Cells("RejectedFlag").Value = 1 Then

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

                        1. Thank you for a bunch of code, unformatted code at that, where it is all about nested IFs and no visible indentation. There is no way to read and understand that as it stands. You should edit your message and apply PRE tags to the code. 2. You should NOT be calling Application.DoEvents(). Not there, not anywhere. It is a very dangerous method, misunderstood by most everyone. If you think you need it, something is wrong with your code and adding it is bound to make things worse as it disturbs the natural flow of events. So remove it everywhere! And remove it completely, don't just turn it into a comment, as if there would still be some value left in it. 3. If you are assigning new cell values in there, that will cause a new barrage of events being fired, which you probably don't want. You certainly don't want an avalanche of events (as a StackOverflow would result). One way to handle it could be this:

                        Dim currentStatus as String = ... ' save the content of status cell
                        Dim newStatus as String = currentStatus
                        ...
                        ' lots of conditional code, which does not change the status cell;
                        ' if a new status is required, store it in newStatus.
                        ...
                        If newStatus <> currentStatus
                        ' now store the new status in its cell (this will cause more events, however there
                        ' will be only one round of them as you now test for an actual change)
                        Endif

                        :)

                        Luc Pattyn [My Articles] Nil Volentibus Arduum

                        H 1 Reply Last reply
                        0
                        • L Luc Pattyn

                          1. Thank you for a bunch of code, unformatted code at that, where it is all about nested IFs and no visible indentation. There is no way to read and understand that as it stands. You should edit your message and apply PRE tags to the code. 2. You should NOT be calling Application.DoEvents(). Not there, not anywhere. It is a very dangerous method, misunderstood by most everyone. If you think you need it, something is wrong with your code and adding it is bound to make things worse as it disturbs the natural flow of events. So remove it everywhere! And remove it completely, don't just turn it into a comment, as if there would still be some value left in it. 3. If you are assigning new cell values in there, that will cause a new barrage of events being fired, which you probably don't want. You certainly don't want an avalanche of events (as a StackOverflow would result). One way to handle it could be this:

                          Dim currentStatus as String = ... ' save the content of status cell
                          Dim newStatus as String = currentStatus
                          ...
                          ' lots of conditional code, which does not change the status cell;
                          ' if a new status is required, store it in newStatus.
                          ...
                          If newStatus <> currentStatus
                          ' now store the new status in its cell (this will cause more events, however there
                          ' will be only one round of them as you now test for an actual change)
                          Endif

                          :)

                          Luc Pattyn [My Articles] Nil Volentibus Arduum

                          H Offline
                          H Offline
                          harvid
                          wrote on last edited by
                          #17

                          Thanks Pete and Luc. I'm done with the changes as you suggested.

                          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