Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
160
Unable to set UltraGrid CheckBox column to True after saving it as False
posted

In my project, there is an UltraGrid, from the Infragistics package (I know this isn't very commonly used, so not sure that asking here will get any answers), but, this UltraGrid is used to allow the input and amending of orders in an ordering system.

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?


In case it helps, this is my code for the CellChange method


    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

Parents
  • 469350
    Verified Answer
    Offline posted

    Hi David, 

    There's nothing in the grid that would prevent the cell from changing twice. It must be something in your code that is doing that. 

    The code you have here is a bit strange and I think what might be happening is that you are causing recursion here. 

    Calling e.Cell.Row.Update() is not really a good idea. And there's certainly no reason to call it twice, as you are doing here. I suspect you are probably doing this because if you don't, the Value property will return the original value of the cell and not the new value. 

    What happens because the Value property of the cell reads from the data source, and the DataSource has not been updated at the time when CellChange fires. That's because for many cells, updating the Value of the data source every time the cell changes would cause problems. For example, if you have a DateTime cell and the user types into that cell, whatever they type would not be a valid value for the cell until they type in enough to make a complete date. So CellChange fires on every keystroke. 

    For CheckBox cells, of course, this is not a problem. But by forcing the entire row to be committed, you might inadvertently cause an exception because some other cell in the same row might have a pending change that isn't valid, yet. 

    I suspect that what might be happening here is that you are committing the value of the cell and then you are SETTING the value of the cell, which may be causing CellChange to fire again recursively, and after that I'm not sure what happens, but this probably isn't the best way to achieve what you want here. 

    A better way to handle this and get the current value of the cell as it appears to the user on-screen is to use the Text property of the cell instead of the Value.

    Dim goodsDelivered As Boolean = Boolean.Parse(e.Cell.Text)

    It looks like what you want to do is prevent the user from checking the Checkbox until the Delivery Date field is filled in. So rather than setting the value on the cell, which could cause recursion, you would be better off setting the Value on the cell's editor. And that way, there's no need to call Update on the Row. 


    Private Sub UltraGrid1_CellChange(sender As Object, e As CellEventArgs) Handles UltraGrid1.CellChange
         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
                        Dim checkEditor As CheckEditor = e.Cell.EditorResolved
                        checkEditor.Value = False
                   End If
              End If
         End If
    End Sub

Reply Children