2
votes

I have an order system, where on the order screen, an order can be entered. To do this, it uses an UltraGrid, where each row is an Order. See the image below.

enter image description here

I know that, somehow, it is possible to make an entire row non-overrideable, so that data in cells cannot be edited, and data cannot be entered into empty cells.

However, I need all of the cells to behave like this, except for one, until this cell has data in it. (Eg; all cells except for "Product Code" should be disabled, and then made available for editing once Product Code has been filled in). What is the code I need to do this?

I've tried using a With statement to set the cells individually to ReadOnly but this didn't seem to work.

EDIT

I have used the code below to make individual columns activation disabled, but I get the error message

Object reference not set to an instance of an object

Can anybody tell me why?

      If ugProducts.ActiveRow.Cells("Product_Code").Value <> "" Then
            ugProducts.DisplayLayout.Bands(0).Columns(1).CellActivation = Activation.Disabled
            ugProducts.DisplayLayout.Bands(0).Columns(2).CellActivation = Activation.Disabled
            ugProducts.DisplayLayout.Bands(0).Columns(3).CellActivation = Activation.Disabled
        Else
        End If

Thanks.

1
First thing you should do is change <> to =, as this is currently setting them to disabled if the value in Product_Code is not empty. What happens if you add .ToString onto the end of .Value? - David
@David Thanks, this still gives the same error but at least the assignment is correct now - user6634034

1 Answers

0
votes

the approach is correct: CellActivation is the right prop to set.

But I think the problem is WHEN you set ;)

You dont talk about WHEN. If you want that the cells are the set once, the right "moment" the InitializeLayout event of UGrid.

In the InitializeLayoutEventArgs you will find the .Layout, use this to set band-column.CellActivation.

Instead if you want to control a specific cell of a specific row, you need to handle this in InitializeRow event and set the Activation of a cell in the row in the eventarg.

While if you need to control the Activation when the user edit cells values, handle it in AfterExitEditMode event.

PS: personal suggestion, use C# instead of VB. more clear, flexible and compact.

Davide