Question

Allow null values in DataGridInt32Column

Posted 3 months ago by Avatar JamesNorbury

Hello,

I've used your DataGrid controls to create a table editor. The user is able to pre-define the types of each column they want, then when the window is opened the columns are created programatically. I would like to allow the user to enter nothing (null) in a cell if they choose to, however this doesn't seem possible when using a DataGridDoubleColumn, DataGridInt32Column, or a DataGridInt64Column.

If no value was ever entered, it displays the hint text "No value" as expected. If a value is entered then is deleted, the entered value is always preserved instead of going back to "No value".

Is there any way to achieve this functionallity? I have tried inheritting from each of the column types and overriding CommitCellEdit to try to see what is happening, however the InitialValue, EffectiveValue and Value properties of the edited cell all show the previous unwanted value, so I am unable to determine what's going on.

Any help would be much appreciated!

Many thanks in advance.

James


Comments (2)

Posted 3 months ago by Actipro Software Support - Cleveland, OH, USA

Hi James,

In the older version, if you override DataGridDateTimeColumn.ApplyStandardValues, you can set this:

((DateTimeEditBox)targetElement).IsNullAllowed = true;

Or alternatively you could add a dependency property to that class for setting IsNullAllowed and bind it like this:

this.ApplyValue(IsNullAllowedProperty, targetElement, DateTimeEditBox.IsNullAllowedProperty);

On a side note, the newer version (i.e. v2018.1) of Editors and the DataGrid interop library has an DataGridDateTimeColumn.IsNullAllowed property that when set to true would allow null values to be set.


Actipro Software Support
Posted 3 months ago by JamesNorbury

Both of these methods worked! I'll opt for the former as it looks like the easiest to read if someone else has to change the behaviour in the future.

Thank you very much for the reply!

James

Information The latest build of this product (2018.1 build 0672) was released 27 days ago, which was after the last post in this thread.

Add a Comment

Please log in to a validated account to post comments.