Moving through datarepeater's items
Is there any way to move through datarepeater's items through code, as we run loop and move through the items in a list / combo box? Thanks Furqan开发者_如何学编程
The code from Schmelter changes the current row, but this might produce undesired effects since it can update the UI and causes other data-handling events to fire. It's not necessary to change the CurrentItemIndex to loop through the DataRepeaterItems. Each DataRepeaterItem is just a Control object in the DataRepeater.Controls collection. Here is an alternative (in C#):
using Microsoft.VisualBasic.PowerPacks;
foreach ( DataRepeaterItem rowItem in dataRepeater1.Controls )
{
int itemIndex = rowItem.ItemIndex;
// If it's bound, get the underlying data object
object dataItem = BindingSource1.List[itemIndex];
// Add code for each rowItem of the dataItem
// All controls on the DataRepeateItem can be obtained from rowItem.Controls
}
This should work:
For i As Integer = 0 To Me.DataRepeater1.ItemCount -1
Me.DataRepeater1.CurrentItemIndex = i
Dim item As DataRepeaterItem = Me.DataRepeater1.CurrentItem
Next
精彩评论