Print Page | Close Window

DateTimePicker in RC Item

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Report Control
Forum Description: Topics Related to Codejock Report Control
URL: http://forum.codejock.com/forum_posts.asp?TID=20153
Printed Date: 23 November 2024 at 2:24pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: DateTimePicker in RC Item
Posted By: kerog
Subject: DateTimePicker in RC Item
Date Posted: 24 September 2012 at 5:24am

How to add custom control to ReportRecordItem? I'd like to add to Item DateTimePicker.

Can you give an example ho to do it?

Regards



-------------
Product: Xtreeme SuitePro (activeX) v. 15.3.1
Platform: MS Vista Buisness (32bit) SP2 PL
IDE: PowerBuilder 11.5.1



Replies:
Posted By: Xander75
Date Posted: 06 November 2012 at 5:20am
Hi,

The following code example shows how to add the DateTimePicker control, but can be used for any control. The original version of this code is found at: http://forum.codejock.com/forum_posts.asp?TID=18679&KW=DateTimePicker&title=adding-control-please-help - http://forum.codejock.com/forum_posts.asp?TID=18679&KW=DateTimePicker&title=adding-control-please-help

However I have changed the code to use the BeginEdit event as this works better than FocusChanging. I also tweaked the code to set the position relative to the ReportControls position, as this is not always set as Left = 0 and Top = 0 on the screen.

The code for showing/hiding the DateTimePicker has been added to a module so this can be reusable for any ReportControl.

Note: I prefer to use the MSComCtl2.DTPicker instead of Codejocks XtremeSuiteControls.DateTimePicker as it allows me to change the colours. I find the XtremeSuiteControls.DateTimePicker Day names to be unreadable when used in conjunction with the SkinFramework control. Plus if you use the XtremeSuiteControls.DateTimePicker you will find the navigation on press of the Tab key doesn't quite work correctly as when the DateTimePicker has focus it then moves out of the ReportControl into other controls even with TabStop set as false! Using the MSComCtl2.DTPicker resolves this when setting TabStop to False allowing the Tab key navigation to flow correctly within the ReportControl even when the DTPicker has focus.

Form Code
' Some test data for this example
Private Sub Form_Load()
    With ReportControl
        .AllowEdit = True
        .AutoColumnSizing = True
        .EditOnClick = True
        .FocusSubItems = True
       
        Dim Column As ReportColumn
        Set Column = .Columns.Add(0, "Column 1", 150, False)
        Set Column = .Columns.Add(1, "Date 1", 90, False)
        Set Column = .Columns.Add(2, "Date 2", 90, False)
       
        .Populate
       
        Dim Record As ReportRecord
        For i = 0 To 100
            Set Record = .Records.Add
            With Record
                .AddItem "Row: " & i
                .AddItem Date
                .AddItem Date
            End With
        Next
       
        .Populate
    End With
End Sub

' Below is the code events required for the DateTimePicker & ReportControl
Private Sub DateTimePicker_Change()
    ReportControl.FocusedRow.Record(ReportControl.FocusedColumn.Index).Value = DateTimePicker.Value
    ReportControl.Populate
End Sub

Private Sub ReportControl_BeginEdit(ByVal Row As XtremeReportControl.IReportRow, ByVal Column As XtremeReportControl.IReportColumn, ByVal Item As XtremeReportControl.IReportRecordItem)
    DateTimePicker.Visible = False
    Select Case Column.Index
        Case 1, 2
            Call ShowDatePicker(ReportControl, DateTimePicker, Row, Column, Item)
    End Select
End Sub

Private Sub ReportControl_FocusChanging(ByVal NewRow As XtremeReportControl.IReportRow, ByVal NewColumn As XtremeReportControl.IReportColumn, ByVal NewItem As XtremeReportControl.IReportRecordItem, Cancel As Boolean)
    Call HideDatePicker(DateTimePicker)
End Sub

Private Sub ReportControl_VScroll(ByVal Section As Long, ByVal Position As Long)
    Call HideDatePicker(DateTimePicker)
End Sub

Module Code
Public Sub HideDatePicker(ByVal DTPicker As XtremeSuiteControls.DateTimePicker)
    With DTPicker
        .Move -10000, -10000, DTPicker.Width, DTPicker.Height
        .ZOrder 1
        .Visible = False
    End With
End Sub

Public Sub ShowDatePicker(ByVal rc As XtremeReportControl.ReportControl, ByVal DTPicker As XtremeSuiteControls.DateTimePicker, ByVal Row As XtremeReportControl.IReportRow, ByVal Column As XtremeReportControl.IReportColumn, ByVal Item As XtremeReportControl.IReportRecordItem)
    Dim l As Long, t As Long, r As Long, b As Long, x As Long, y As Long
    x = Screen.TwipsPerPixelX
    y = Screen.TwipsPerPixelY
   
    rc.Rows(Row.Index).GetItemRect Item, l, t, r, b
    l = l * x
    t = t * y
    r = r * x
    b = b * y

    With DTPicker
        .Move (rc.Left + x) + l, (rc.Top + y) + t, (r - l) + x, (b - t) + y
        .ZOrder 0
        .Visible = True
        .Value = Item.Value
    End With
End Sub



-------------
Product: Xtreme SuitePro (ActiveX) v15.3.1
Platform: Windows 7 64-bit (SP1) Professional Edition
Languages: C#.Net using Visual Studio 2012 & Visual Basic 6.0 (SP6)



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net