DataRepeater addNew Causes DrawtItem to Execute Twice

curlydog

Well-known member
Joined
Jul 5, 2010
Messages
50
Programming Experience
Beginner
Hi,
I'm using a dataRepeater which is unbound to a list of Objects ( as I need to have two types of object in the dataRepeater).

I'm using the following code to populate my dataRepeater
VB.NET:
Private Sub loadDeviceDetails(ByVal owner As Mi2.MiOwner)
............
Dim listDevices As New List(Of Object)
Dim c As Integer = 1
For Each dev As Object In listDevices
            Debug.Print("frmShowCase1.loadDeviceDetails: adding device " & c & " to repdevice")
            c += 1
            repDevice.AddNew()
            Debug.Print("frmShowCase1.loadDeviceDetails: device added from listDevices to repDevice")
        Next
..........

What appears to be happening is that during the drawitem method for the datarepeater the method is being called twice for each item, except fo the first. At this point I'm still designing the code, so I'm just outputting messages to the condsole. Here's the code for my drawitem event
VB.NET:
Private Sub repDevice_DrawItem(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.PowerPacks.DataRepeaterItemEventArgs) Handles repDevice.DrawItem
        Debug.Print("frmShowCase1.repDevice_DrawItem: INTO ROUTINE")
        Debug.Print("frmShowCase1.repDevice_DrawItem: END ROUTINE")
    End Sub

This is the console output I get;
frmShowCase1.loadDeviceDetails: listDevices contains 6 items
frmShowCase1.loadDeviceDetails: adding device 1 to repdevice
frmShowCase1.repDevice_DrawItem: INTO ROUTINE
frmShowCase1.repDevice_DrawItem: END ROUTINE
frmShowCase1.loadDeviceDetails: device added from listDevices to repDevice
frmShowCase1.loadDeviceDetails: adding device 2 to repdevice
frmShowCase1.repDevice_DrawItem: INTO ROUTINE
frmShowCase1.repDevice_DrawItem: END ROUTINE
frmShowCase1.repDevice_DrawItem: INTO ROUTINE
frmShowCase1.repDevice_DrawItem: END ROUTINE
frmShowCase1.loadDeviceDetails: device added from listDevices to repDevice
frmShowCase1.loadDeviceDetails: adding device 3 to repdevice
frmShowCase1.repDevice_DrawItem: INTO ROUTINE
frmShowCase1.repDevice_DrawItem: END ROUTINE
frmShowCase1.repDevice_DrawItem: INTO ROUTINE
frmShowCase1.repDevice_DrawItem: END ROUTINE
frmShowCase1.loadDeviceDetails: device added from listDevices to repDevice
frmShowCase1.loadDeviceDetails: adding device 4 to repdevice
frmShowCase1.repDevice_DrawItem: INTO ROUTINE
frmShowCase1.repDevice_DrawItem: END ROUTINE
frmShowCase1.repDevice_DrawItem: INTO ROUTINE
frmShowCase1.repDevice_DrawItem: END ROUTINE
frmShowCase1.loadDeviceDetails: device added from listDevices to repDevice
frmShowCase1.loadDeviceDetails: adding device 5 to repdevice
frmShowCase1.repDevice_DrawItem: INTO ROUTINE
frmShowCase1.repDevice_DrawItem: END ROUTINE
frmShowCase1.repDevice_DrawItem: INTO ROUTINE
frmShowCase1.repDevice_DrawItem: END ROUTINE
frmShowCase1.loadDeviceDetails: device added from listDevices to repDevice
frmShowCase1.loadDeviceDetails: adding device 6 to repdevice
frmShowCase1.repDevice_DrawItem: INTO ROUTINE
frmShowCase1.repDevice_DrawItem: END ROUTINE
frmShowCase1.repDevice_DrawItem: INTO ROUTINE
frmShowCase1.repDevice_DrawItem: END ROUTINE
frmShowCase1.loadDeviceDetails: device added from listDevices to repDevice
frmShowCase1.loadDeviceDetails: END ROUTINE

For some reason the first drawItem runs once, as expected. therafter it runs twice for each new item that is added to the dataRepeater.

Can anyone poin tme in the right direction?

Thanks
Jason
 
DrawItem event is raised whenever an item needs to be drawn. When item is added all visible items redraws (because of scroll), so your results signifies that two items are concurrently visible, if you check ItemIndex you'll see which items redraws as item is added and view scrolls down. As expected, when there is only one item, there can only be one DrawItem event raised.
DataRepeater.DrawItem Event (Microsoft.VisualBasic.PowerPacks)
 
Back
Top