4

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

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Furqan Sehgal
  • 4,917
  • 33
  • 108
  • 167

2 Answers2

5

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  
    }
C Perkins
  • 3,733
  • 4
  • 23
  • 37
3

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
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939