Visual Basic Development Bookmark and Share   
 Home > Visual Basic Power Packs > Problem occured when i scroll through the records in VB power pack Data Repeater Control
 

Problem occured when i scroll through the records in VB power pack Data Repeater Control

Hello guys, I am using vb Power Pack Data Repeater control in my project, when i scroll through the records it is showing some un predictable behaviour,the values in the textfields are missing, The following code is called each time i scroll through the records, PLease help me in this regard, and also give me sample code on how to add new record and also how to update existing records

Thanks

Private Sub DataRepeater1_DrawItem(ByVal sender As System.Object, ByVal e As Microsoft.VisualBasic.PowerPacks.DataRepeaterItemEventArgs) Handles DataRepeater1.DrawItem

Dim item As DataRowView = bs.Item(e.DataRepeaterItem.ItemIndex)
Try

If Not IsDBNull(item.Item(0)) Then
DirectCast(e.DataRepeaterItem.Controls("TextBox2"), TextBox).Text = item.Item(0)
Else
DirectCast(e.DataRepeaterItem.Controls("TextBox2"), TextBox).Text = String.Empty
End If
If Not IsDBNull(item.Item(1)) Then
DirectCast(e.DataRepeaterItem.Controls("TextBox1"), TextBox).Text = item.Item(1)
Else
DirectCast(e.DataRepeaterItem.Controls("TextBox1"), TextBox).Text = String.Empty
End If
If Not IsDBNull(item.Item(1)) Then
DirectCast(e.DataRepeaterItem.Controls("ID"), Label).Text = item.Item(1)
Else
DirectCast(e.DataRepeaterItem.Controls("ID"), Label).Text = String.Empty
End If

'If flg = True Then
' If e.DataRepeaterItem.ItemIndex = ItmIndex Then
' DirectCast(e.DataRepeaterItem.Controls("TextBox1"), TextBox).Text = txtname
' End If
'End If

Catch ex As Exception

End Try

End Sub
Ilyas Bmd  Monday, March 10, 2008 7:47 AM

Are you using virtual mode? If you want to show data in virtual mode, you can handle DataRepeater.ItemValueNeeded event. The DrawItem event is used to change the appearance. Let me know if you have further questions.

yfdong_MSFT  Thursday, March 13, 2008 2:17 AM

Are you using virtual mode? If you want to show data in virtual mode, you can handle DataRepeater.ItemValueNeeded event. The DrawItem event is used to change the appearance. Let me know if you have further questions.

yfdong_MSFT  Thursday, March 13, 2008 2:17 AM
Maybe a litle late, but i found a workaround for scrolling in a datarepeater without getting confused by the information in the form messed up by the scrollbar actions.
Make sure that in the datarepeater1_drawitem handler the contents etc of the controls are set.

The following code will work for every form with a datarepeater with a strange scroll behaviour. Place thefollowing lines in the code of the form:
(regards, Frank)

Private Sub DataRepeater1_Scroll(ByVal sender As Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles DataRepeater1.Scroll

'the relative position of the datarepeater.currentitemindex is calculated

If DataRepeater1.ItemCount > 0 Then

Dim j As Int32 = 0 'calculated index for the itemindex

Dim i As Int32 = 0 'start index for looping through the datarepeater index

Dim s As Int16 = 0 'direction for the step in the for next

j = _

Math.Round(DataRepeater1.VerticalScroll.Value / _

(DataRepeater1.VerticalScroll.Maximum - _

DataRepeater1.VerticalScroll.LargeChange) * _

DataRepeater1.ItemCount, 0) _

- 1

'To make sure that j reaches a valid currentitemindex

If j < 0 Then j = 0

If j > DataRepeater1.ItemCount - 1 Then j = DataRepeater1.ItemCount - 1

'loop trough all the datarepeater rows

'from the current itemindex position to the calculated position

'in order to raise the DrawItem event for each row to

'make sure the datarepeater cunrrent controls are propperly filled

If j < DataRepeater1.CurrentItemIndex Then

s = -1

For i = DataRepeater1.CurrentItemIndex To j Step s

DataRepeater1.CurrentItemIndex = i

Next i

Else

s = 1

End If

For i = DataRepeater1.CurrentItemIndex To j Step s

DataRepeater1.CurrentItemIndex = i

Next i

End
If

End
Sub

Frank the beerhunter  Thursday, September 03, 2009 8:55 AM
Hi Frank,

I think it is better to understand how the DataRepeater works, otherwise, you may get some unexpected result.

Please see the reference documents on MSDN: http://msdn.microsoft.com/en-us/library/cc488279.aspx

We also have some blog post at out team blog. e.g.

http://blogs.msdn.com/vsdata/archive/2009/09/08/writing-event-handler-for-controls-in-a-datarepeateritem.aspx

http://blogs.msdn.com/vsdata/archive/2009/08/27/how-to-change-appearance-of-all-datarepeater-items-at-run-time.aspx

http://blogs.msdn.com/vsdata/archive/2009/08/12/datarepeater-control-for-windows-forms.aspx

John Chen -- See my team blog: http://blogs.msdn.com/vsdata. All my posts are provided "AS IS" with no warranties, and confer no rights.
John Chen MS  Wednesday, September 09, 2009 4:39 AM

You can use google to search for other answers

Custom Search

More Threads

• Power Pack 2 application install problem
• How to print scrollable textbox
• How Can I Suppress the 2005 Printing Status Dialog?
• Printing Active MDT Child in VB?
• Deploying PowerPacks
• datarepeater template area
• Detecting click events in DataRepeater
• open
• getting error that cvf.exe is missing
• values being ignored