Partager via


Grid Cell Alignment response

This post: Is this a bug in the Grid Cell alignment? discusses a grid cell alignment issue.

When the grid is created and there is a cursor open in the current work area, a grid column will be created for each field in the cursor. The alignment for the column is initialized based on the column type. Integer fields are set to be right justified. When the subsequent code changes the column control source from integer to character, the alignment is not changed.

Below is the same code with a single change: after the ControlSource of the column is changed (which changes the data type from numeric to character) the Alignment is set explicitly.

PUBLIC oForm

oForm=CREATEOBJECT("MyForm")

oForm.show

DEFINE CLASS MyForm as Form

      left=100

      height=200

      width=600

      allowoutput=.f.

      PROCEDURE init(cFilename)

            IF .t.

                  CREATE CURSOR test (num i,name c(40))

                  INSERT INTO test VALUES (0,"name")

                  INSERT INTO test VALUES (1,"name")

            ELSE

                  CREATE CURSOR test (num c(10),name c(40))

                  INSERT INTO test VALUES ("0","name")

                  INSERT INTO test VALUES ("1","name")

            ENDIF

            this.AddObject("grd","grid")

            WITH this.grd as grid

                  .Visible=1

                  .Height=thisform.Height

                  .Width=thisform.Width

                  WITH this.grd.column1 as Column

                        .header1.caption="Name"

                        .ControlSource="'some data '"

                        .Alignment=3 && add this line after the control source is changed

                        .Width=250

                  ENDWITH

                  LOCATE

            ENDWITH

ENDDEFINE