Sub createGrid(Col As Int, Row As Int)
Dim now As Long = DateTime.Now
' Public DPpnl As Panel
Dim gap As Int = 2dip
Dim wday As Label
Public spn As Spinner
Dim close As Button
DPpnl.Initialize("DPpnl")
wday.Initialize("wday")
close.initialize("close")
DPpnl.Color = xui.Color_white
DPpnl.Elevation = 20dip
Activity.AddView(DPpnl,40dip, 0dip, 280dip - gap, 380dip - gap)
Dim spnWidth As Int = DPpnl.Width / 2 - gap
Dim btnWH As Int = DPpnl.Width/Col
Public btns As List
btns.Initialize
'========add the views ==============
'create and set Month selector spinner ==================
spn.initialize("spnM")
DPpnl.AddView(spn, 0dip, 0dip, spnWidth, 40dip)
spn.Addall(mths)
spn.SelectedIndex = (activeMonth-1)
'create and set year selector spinner =============
spn.initialize("spnY")
DPpnl.AddView(spn, spnWidth- gap , 0dip, spnWidth - gap , 40dip)
spn.Addall(Array As Int( DateTime.GetYear(now)- 1, DateTime.GetYear(now)))
spn.selectedindex = (DateTime.GetYear(now))
'create and set the 42 possible month days buttons
Dim d As Int = 0
Dim top As Int = 40dip
For r = 1 To Row
top = top + 40dip
For c = 0 To Col - 1
d = d + 1
Dim btn As Button
btn.Initialize("btn")
DPpnl.AddView(btn, c*40dip, top + gap, btnWH, btnWH)
btn.TextSize = 10
btns.Add(btn)
btn.Text = ""
Next
Next
DPpnl.AddView(close, spnWidth, top + 40dip, spnWidth,40dip)
close.Text = "Close"
'create string of month and force a double digit
Dim aMonth As String = activeMonth
If aMonth.Length = 1 Then aMonth = $"0${aMonth}"$
'no bleedin' clue, mate!!
Dim olddate As String = DateTime.DateFormat
DateTime.DateFormat = "MM/dd/yyyy"
TT = myParseDate($"${aMonth}/01/${activeYear}"$)
Dim day1 As Int = DateTime.GetDayOfWeek(TT)-1
Dim last1 As Int = DateUtils.numberofdaysinmonth(activeMonth,activeYear)
DateTime.dateformat = olddate
'=======fill the spots ===============
For x = 0 To 6
Dim wday As Label
wday.Initialize("wday")
DPpnl.AddView(wday, x * btnWH + gap, 40dip + gap, btnWH, btnWH)
wday.Text = $" ${days.get(x)}"$
Next
'add in day of month numbers
For x = 0 To last1-1
btns.Get(x+day1).As (Button).text = x+1
Next
Log($"Actual month: ${DateTime.GetMonth(now)}, activeMonth: ${activeMonth}"$)
If DateTime.GetMonth(now) = activeMonth Then
btns.Get(day1).As(Button).Color = xui.Color_Red
End If
End Sub
Sub close_Click
Log("Closed")
DPpnl.RemoveView
DPpnl.visible = False
DPpnl.RemoveAllViews
End Sub