Locked DataRepeater scroll problem

  • Monday, June 27, 2011 11:11 AM
     
     

    Hello everybody,

    i have a problem with my DataRepeater control.

    DataRepeater is in tabs page on second tab. And in this tab is splitContainer which include three buttones and DataRepeater self.

    1. If I open the tab data load perect.

    PIC 1 http://public.i-page.net/stav1.JPG

    2. Next I check first two rows (button is chcebox)

    PIC 2 http://public.i-page.net/stav2.JPG

     3. Next I scroll down and see another row checkedm but this row I dont check.

    PIC 3 http://public.i-page.net/stav3.JPG

    4 After I return to top (first two) only second was checked.

    PIC 4 http://public.i-page.net/stav4.JPG

    This error is showing random on random rows after scroll.

     

    DataRepeater is not virtual but same error with set to virtual.

    Thanks for any help.

     


All Replies

  • Wednesday, June 29, 2011 6:53 AM
    Moderator
     
     Answered Has Code

    Hi Cs_Paladin,

    Welcome to the MSDN Forum.

    First of all, the error is not on random rows.

    As you know, the datarepeater only have several item controls, but it can display many items. Generally, the datarepeater will only create the specific count of the items instances, and then reuse them. For example, if the datarepeater only can display four item one time, so the datarepeater will only create four or five different instances, when you scoll to the 5-9 items, the datarepeater will reuse the former instance to display the new item values. At this time the select states will be changed. This is why you meet the scenario.

    To avoid this, please try to change to a textbox to log the state. Or write the state back to databindings like the following code snippet:

      Public dt1 As New DataTable
      Private Sub WithCheckBox_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim dview As DataView
    
        Dim col1 As DataColumn = New DataColumn("Original", Type.GetType("System.Int32"))
        Dim col2 As DataColumn = New DataColumn("Current", Type.GetType("System.Boolean"))
    
        dt1.Columns.Add(col1)
        dt1.Columns.Add(col2)
    
        Dim i As Integer = 1
        Dim radom As New Random(Now.Millisecond)
        Dim radom2 As New Random(Now.Millisecond)
        While i < 20
          'dt1.Rows.Add(i, radom2.Next(2) = 1)
          dt1.Rows.Add(i, False)
          i += 1
        End While
        dview = New DataView(dt1)
        dview.AllowEdit = True
    
        Me.Label1.DataBindings.Add("Text", dview, "Original", True)
        Me.CheckBox1.DataBindings.Add("Checked", dview, "Current", True)
    
        Me.Label1.DataBindings(0).DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged
        Me.CheckBox1.DataBindings(0).DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged
    
        Me.DataRepeater1.DataSource = dview
    
      End Sub
    
      Private Sub CheckBox1_CheckedChanged(sender As Object, e As System.EventArgs) Handles CheckBox1.CheckedChanged
        Me.CheckBox1.DataBindings(0).WriteValue()
    
        For i = 0 To 18
          Console.WriteLine(dt1.Rows(i).Item(0) & " " & dt1.Rows(i).Item(1))
        Next
        Console.WriteLine("--------------------------------")
      End Sub
    

    I hope this will be helpful.

    Best regards,

     


    Mike Feng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • Tuesday, October 09, 2012 5:56 AM
     
      Has Code

    Hi Mike,

    It just aint no luck of trying your code. I am having this problem too. May i share with you my code? I can;t make the checkbox working..

    bind the datarepeater to the data table

    drtRoom.DataSource = dt_LARooms

    then use the itemvalueneeded to allocate the field

    Select Case e.Control.Name
        Case drtRoom.ItemTemplate.Controls ("lblNo").Name
             e.Value = e.ItemIndex + 1 & "."
        Case drtRoom.ItemTemplate.Controls(("lblSpaceID").Name
                e.Value = dt_LARooms.Rows(e.ItemIndex)("SPACE_ID").ToString
        End Select

    then use itemvaluepush to save data to datatable

    Private Sub drtRoom_ItemValuePushed(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.PowerPacks.DataRepeaterItemValueEventArgs) Handles drtRoom.ItemValuePushed
        Select Case e.Control.Name
            Case "txtResidentCode"
                dt_LARooms.Rows(e.ItemIndex)("RESIDENT_CODE") = e.Control.Text
            Case "cmbStatus"
                dt_LARooms.Rows(e.ItemIndex)("rStatus") = e.Control.Text
        End Select
    End Sub