error when commiting the row to the original data store(urgent)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cutequencher
    New Member
    • Jun 2007
    • 4

    error when commiting the row to the original data store(urgent)

    i am having this error when i am about to delete a data row

    inline with this is a message box saying:
    object reference not set to an instance of an object. do you want to correct the value?

    if i click yes, it will delete the row if no it will ignore the deletion

    i've already checked all of my declarations and pretty sure that i've declared everything right. please help me about this. thanx!
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    A "data row" in what? And using what version of VB?

    Comment

    • cutequencher
      New Member
      • Jun 2007
      • 4

      #3
      sorry for the late response.

      here's my code:

      Private Sub delCol_ButtonCo lumnClick(ByVal sender As Object, ByVal e As Leadit.Extended DataGrid.Button ColumnEventArgs ) Handles delCol.ButtonCo lumnClick
      Dim row As Integer
      Dim hourdiffBtn As Integer
      Dim sBtn As DateTime
      Dim eBtn As DateTime
      Dim res As MsgBoxResult
      row = Me.dtgCustomSch ed.CurrentRowIn dex
      res = MsgBox("Are you sure you want to delete the schedule on " + Me.dtgCustomSch ed.Item(row, 0), MsgBoxStyle.Yes No)
      If res = MsgBoxResult.Ye s Then
      sBtn = Date.Parse(Me.d tgCustomSched.I tem(row, 1))
      eBtn = Date.Parse(Me.d tgCustomSched.I tem(row, 2))
      hourdiffBtn = getHrValue(sBtn , eBtn)
      lastRowNumber = lastRowNumber - 1
      Me.remainingHou r2 = Me.remainingHou r2 + hourdiffBtn
      Me.txtLookUpHou rs.Text = remainingHour2. ToString
      addSchedule.Tab le("ttcpcustomi zedschedule").R ows.R emoveAt(row)

      Else
      Exit Sub
      End If
      End Sub


      dtgcustomsched is the name of my datagrid
      addsched is the name of the dataset

      i made one of the datagrid cell as a customized button.. it already work fine with my other codes.. the problem only occur here

      the error occurs on the line in bold.

      also, this error only appears when i delete the last row on the datagrid, but if i delete anything rather than the last row everything works fine and no error is being detected

      please help. thanx!

      i am using vb.net 2002

      Comment

      • Motoma
        Recognized Expert Specialist
        • Jan 2007
        • 3236

        #4
        Originally posted by cutequencher
        also, this error only appears when i delete the last row on the datagrid, but if i delete anything rather than the last row everything works fine and no error is being detected
        Not knowing anything about VB.NET (other than the .NET framework) it sounds like you have an indexing issue. That is to say, you are trying to remove a row outside the boundaries of the dataset. Try deleting the first row. Does the proper row get removed, or are you off by one?

        Comment

        • SkinHead
          New Member
          • Jun 2007
          • 39

          #5
          Are the two indexes zero-based

          row = Me.dtgCustomSch ed.CurrentRowIn dex
          .
          .
          .
          addSchedule.Tab le("ttcpcustomi zedschedule").R ows.RemoveAt(ro w)

          If they have different bases, then you might need to do the following :

          row = Me.dtgCustomSch ed.CurrentRowIn dex - 1

          Or

          addSchedule.Tab le("ttcpcustomi zedschedule").R ows.RemoveAt(ro w + 1)

          Comment

          Working...