RunPMC
2018-09-19T16:56:00Z
I have a version 6.50.0063 iGrid control on a form in MS Access 2013 (32-bit). Columns are not defined in code. I populate the grid with a procedure call fired from a button click event. Directly after populating it, I attempt to set the horizontal alignment and string format of some of its columns. There are no errors generated, but the property changes don't take effect -- specifically, the horizontal alignment and string formats of these columns are not applied. Every time I re-populate the grid after that with the same button click procedure call, the property changes will take effect.

How can I get it to take effect the first time?

Here is the procedure that populates the grid and sets the horizontal alignment and string format properties:
Dim grd As iGrid
Dim rs As DAO.Recordset
Dim l As Long

Set rs = CurrentDb.OpenRecordset("q_ScheduleAnalysisSummary", dbOpenSnapshot)
Set grd = Me.iGridScheduledJobs.Object
With grd
	.Clear
	.BeginUpdate
	.FillFromRS rs
	For l = 1 To .ColCount
		Select Case .ColHeaderText(l)
			Case "START", "FINISH", "ACTUAL START", "POSSIBLE START", "CLOSED"
				.ColDefaultCell(l).eAlignH = 2
				.ColDefaultCell(l).sFmtString = "yyyy/mm/dd"
		End Select
		.AutoWidthCol l
	Next l
	.DefaultRowHeight = .GetOptimalCellHeight()
	.EndUpdate
End With

Igor/10Tec
2018-09-20T14:09:24Z
The column default cell is an object whose properties are copied into all new cells. When you call the FillFromRS method the first time, the method creates columns and populates the grid, but the ColDefaultCell object does not contain required settings for cell properties by that time. Actually you set them after the cells have been created, and that's why you do not see the effect the first time.

To fix the problem, you need to ask FillFromRS to create only columns for the specified recordset first, then set the required column default cell properties and add rows to the grid after that. To implement the first task, use the 2nd parameter of the fillFromRS method that allows you to specify population mode. Use the igFillRSRecreateColsOnly mode.

The corresponding part of code that defines columns and populates iGrid should look like this:

.FillFromRS rs, igFillRSRecreateColsOnly
For l = 1 To .ColCount
	Select Case .ColHeaderText(l)
		Case "START", "FINISH", "ACTUAL START", "POSSIBLE START", "CLOSED"
			.ColDefaultCell(l).eAlignH = 2
			.ColDefaultCell(l).sFmtString = "yyyy/mm/dd"
	End Select
	.AutoWidthCol l
Next l
.FillFromRS rs
RunPMC
2018-09-20T17:52:15Z
Thanks for the lesson. Working well now!