joe joe - 2 months ago 22
Vb.net Question

Reset the value of an UltraGrid calendar picker to blank

One of the columns in my

UltraGrid
has a cell style of a calendar picker, since the datatype of that field is
Date/Time
. The initial value of this is _ _ /_ _ /_ _

When I click on one of the checkboxes of a checkbox style cell (representing a boolean in the database), I then can select a date from the date cell, and this works fine. However, when I click the checkbox again (setting it from a
True
value, to
False
), I then want the date value of the same row to reset back to _ _ / _ _ / _ _

How is this done, or is it even possible? I've tried using things such as
.Reset
which doesn't appear to be a valid method, as well as setting to
.Value = Nothing
, which also didn't work.

Answer

First you need to allow null values in your date column. To do so you may handle InitializeLayout event of the grid and set the Nullable property of your date column to Null like this:

//  Set Nullable property of the column to Null
e.Layout.Bands[0].Columns["Date"].Nullable = Infragistics.Win.UltraWinGrid.Nullable.Null;

Note, you can also set some custom string for cells with null value by setting NullText like this:

//  You may also set some custom string for Null cells.
e.Layout.Bands[0].Columns["Date"].NullText = "__/__/____";

Finally when the check box is set to false you will need to set the corresponding date cell value to DBNull like this:

//  Get the row of the active cell
var row = this.ultraGrid1.ActiveCell.Row;

//  Set the corresponding Date cell value to DBNull
row.Cells["Date"].Value = DBNull.Value;
Comments