Cannot set UltraGrid Checkbox value to True after saving the initial data

随声附和 提交于 2019-12-13 07:20:33

问题


My project contains a form which allows the entering of orders, using an UltraGrid.

One column is a checkbox style column, to represent whether or not the order has been delivered.

When the order reaches 'Stage 4 - Awaiting Goods Delivery', the user can set the column value to True, which in turn prompts a new window, to allow the user to enter the volume and value of the delivery. If the order hasn't been fully delivered, the checkbox is set back to False, and the order line turns yellow (Eg; 5 gates have been ordered, but only 3 delivered = False, but a yellow order line).

After saving the order, closing it and going back into it, I'm trying to set the Checkbox to True, to update the order to add on the rest of the delivery (the final 2 gates have been delivered), but as soon as I set it to True, it instantly becomes False again (When stepping through the following code in the CellChange method, it says the cell value is False too).

So, why can I only change the value once? After it's been saved, why can the value then not be changed again? Is it do with the fact that it's saved as False in the database?

Try
  If e.Cell.Column.ToString = "Goods_Delivered" Then
     e.Cell.Row.Update()

       If e.Cell.Value = True Then
           If IsDBNull(e.Cell.Row.Cells("Final_Delivery").Value) Then
              MsgBox("Please enter a delivery date", MsgBoxStyle.OkOnly, "Invalid Date")
                    e.Cell.Row.Cells("Goods_Delivered").Value = False
           Else
            Dim f As New dlgDelivery(e.Cell.Row, Me, e.Cell.Row.Cells("Final_Delivery").Value, con, orderNumber, e.Cell.Row.Cells("Product_Code").Value, exTotal)
                f.ShowDialog()
           End If

           e.Cell.Row.Update()

        cmdCheck_Click(sender, New EventArgs)
        cmdTotals_Click(sender, New EventArgs)

  ElseIf e.Cell.Value = False Then
      ugProducts.ActiveRow.Cells("Final_Delivery").Value = DBNull.Value
       productCode = ugProducts.ActiveRow.Cells("Product_Code").Value
       database.NotDelivered(orderNumber, productCode, con)
     Exit Sub
  Else
  End If

回答1:


The error within this was with e.Row.Update().

I was committing the value of the cell and then you are SETTING the value of the cell, which was causing CellChange to fire again recursively, and after that I'm not sure what happens, but there was more effective ways of writing this code.

Try
  If e.Cell.Column.Key = "Goods_Delivered" Then
   Dim goodsDelivered As Boolean = Boolean.Parse(e.Cell.Text)
     If goodsDelivered = True Then
      If IsDBNull(e.Cell.Row.Cells("Final_Delivery").Value) Then
       MsgBox("Please enter a delivery date", MsgBoxStyle.OkOnly, "Invalid Date")
       Dim checkEditor As CheckEditor = e.Cell.EditorResolved
       checkEditor.Value = False
      Else
       Dim f As New dlgDelivery(e.Cell.Row, Me, e.Cell.Row.Cells("Final_Delivery").Value, con, orderNumber, e.Cell.Row.Cells("Product_Code").Value, exTotal)
       f.ShowDialog()
      End If
     ElseIf goodsDelivered = False Then
       ugProducts.ActiveRow.Cells("Final_Delivery").Value = DBNull.Value
                productCode = ugProducts.ActiveRow.Cells("Product_Code").Value
                database.NotDelivered(orderNumber, productCode, con)
             Exit Sub
         End If
      End If

Catch ex As Exception
   errorLog(ex)

 End Try


来源:https://stackoverflow.com/questions/39727025/cannot-set-ultragrid-checkbox-value-to-true-after-saving-the-initial-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!