RaymondC
  • RaymondC
  • Advanced Member Topic Starter
2018-10-16T22:48:42Z
I am a little confused about what is the default data type for the cells in a column. The help file says: "Cell values are containers of the Variant data type."

But it also says: "You can face a problem when iGrid does not allow you to enter a fractional number in a cell that stores a numeric value. This occurs if you have initialized the cell with an integer (non-fractional) value."

It seems that the data type of a cell is assigned when the cell is initialized and is determined by the first value entered into a cell. So the data type of a cell is in fact not a variant but rather dynamically assigned by whatever is the first value entered into a cell in that column?

I want to initialize the cells of one column to hold the double data type. The help file says that I can do this in two ways:

iGrid1.ColDefaultCell(1).vValue = 0#
iGrid1.ColDefaultCell(1).vValue = CDbl(0)

Does this actually put a value of zero into all the cells of column 1 or only assign the double data type?

Thanks.

Ray

EDIT: I tested the code above and all the cells get a value of zero. Is it possible to initialize the cells of a column to the double data type but to have default null values?
Igor/10Tec
2018-10-17T09:51:54Z
The iGrid cell value is a Variant container and thus can contain a value of any data type. The data type of a cell is determined by the value it currently contains, and there is no other property to set the data type of the cell. You specify it with the value you put into the cell.

When the user edits the cell value, iGrid tries to convert the entered value into the corresponding value of the cell data type (the type of the value it currently contains). This explains the phrase "You can face a problem when iGrid does not allow you to enter a fractional number in a cell that stores a numeric value. This occurs if you have initialized the cell with an integer (non-fractional) value." If a cell contains an integer value, you can enter only an integer value. Even if you type in something like "12.5", it will be rounded and saved as integer. To allow entering of fractional numbers, the original cell value must be Single or Double.

引用:

Is it possible to initialize the cells of a column to the double data type but to have default null values?



After my explanation above it's clear that you can't do this if you want to build this functionality using only cell values. However, there is nothing impossible to implement with the iGrid events. If you initialize iGrid cells with say the Variant Empty value, you can allow the user to enter double values into them with the following event handler:

Private Sub iGrid1_BeforeCommitEdit(ByVal lRow As Long, ByVal lCol As Long, eResult As iGrid650_10Tec.EEditResults, ByVal sNewText As String, vNewValue As Variant, ByVal lConvErr As Long, ByVal bCanProceedEditing As Boolean, ByVal lComboListIndex As Long)

   vNewValue = CDbl(sNewText)

End Sub

This is a simplest event handler body that does what you need, and sure, you need to add some conversion error handling in a real-world app.
RaymondC
  • RaymondC
  • Advanced Member Topic Starter
2018-10-17T18:43:40Z
I understand now. Thank you.