Non databinding performance

6 posts, 1 answers
  1. Clive
    Clive avatar
    12 posts
    Member since:
    Sep 2011

    Posted 26 Oct 2011 Link to this post

    Hi,

    I was wondering if the list view will improve its non-binding performance.

    Our application uses the .NET list view and I'm seeing how well we can move to the telerik controls. So far the performance is terrible. When I moved our tree view to telerik, the performance was great, so this was a bit disappointing.

    In my example below, the time for button1 to complete loading the telerik list view takes 18678ms, whereas the traditional Microsoft list view in button2 is 46ms.

    When I add in some threading, the telerik list view needs about 65ms to draw before the form remains interactive, and takes 17765ms to add the list items. whereas the Microsoft list view needs 1ms per item and takes 136ms in total.

    Will Telerik be improving this or should I find another way? I can't remember why I didn't try data binding, but I'll spend the afternoon reinvestigating it.

    Imports Telerik.WinControls.UI
    Public Class Form3
        Inherits System.Windows.Forms.Form
      
        'Form overrides dispose to clean up the component list.
        <System.Diagnostics.DebuggerNonUserCode()> _
        Protected Overrides Sub Dispose(ByVal disposing As Boolean)
            Try
                If disposing AndAlso components IsNot Nothing Then
                    components.Dispose()
                End If
            Finally
                MyBase.Dispose(disposing)
            End Try
        End Sub
      
        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer
      
        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        <System.Diagnostics.DebuggerStepThrough()> _
        Private Sub InitializeComponent()
            Dim ListViewDetailColumn1 As Telerik.WinControls.UI.ListViewDetailColumn = New Telerik.WinControls.UI.ListViewDetailColumn("Column 0", "Column 0")
            Dim ListViewDetailColumn2 As Telerik.WinControls.UI.ListViewDetailColumn = New Telerik.WinControls.UI.ListViewDetailColumn("Column 1", "Column 1")
            Dim ListViewDetailColumn3 As Telerik.WinControls.UI.ListViewDetailColumn = New Telerik.WinControls.UI.ListViewDetailColumn("Column 2", "Column 2")
            Dim ListViewDetailColumn4 As Telerik.WinControls.UI.ListViewDetailColumn = New Telerik.WinControls.UI.ListViewDetailColumn("Column 3", "Column 3")
            Dim ListViewDetailColumn5 As Telerik.WinControls.UI.ListViewDetailColumn = New Telerik.WinControls.UI.ListViewDetailColumn("Column 4", "Column 4")
            Dim ListViewDetailColumn6 As Telerik.WinControls.UI.ListViewDetailColumn = New Telerik.WinControls.UI.ListViewDetailColumn("Column 5", "Column 5")
            Dim ListViewDetailColumn7 As Telerik.WinControls.UI.ListViewDetailColumn = New Telerik.WinControls.UI.ListViewDetailColumn("Column 6", "Column 6")
            Dim ListViewDetailColumn8 As Telerik.WinControls.UI.ListViewDetailColumn = New Telerik.WinControls.UI.ListViewDetailColumn("Column 7", "Column 7")
            Dim ListViewDetailColumn9 As Telerik.WinControls.UI.ListViewDetailColumn = New Telerik.WinControls.UI.ListViewDetailColumn("Column 8", "Column 8")
            Dim ListViewDetailColumn10 As Telerik.WinControls.UI.ListViewDetailColumn = New Telerik.WinControls.UI.ListViewDetailColumn("Column 9", "Column 9")
            Me.ListView1 = New Telerik.WinControls.UI.RadListView()
            Me.ListView2 = New System.Windows.Forms.ListView()
            Me.RadButton1 = New Telerik.WinControls.UI.RadButton()
            Me.RadButton2 = New Telerik.WinControls.UI.RadButton()
            Me.ColumnHeader1 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader)
            Me.ColumnHeader2 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader)
            Me.ColumnHeader3 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader)
            Me.ColumnHeader4 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader)
            Me.ColumnHeader5 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader)
            Me.ColumnHeader6 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader)
            Me.ColumnHeader7 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader)
            Me.ColumnHeader8 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader)
            Me.ColumnHeader9 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader)
            Me.ColumnHeader10 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader)
            Me.RadButton3 = New Telerik.WinControls.UI.RadButton()
            Me.RadButton4 = New Telerik.WinControls.UI.RadButton()
            Me.RadTextBox1 = New Telerik.WinControls.UI.RadTextBox()
            Me.RadTextBox2 = New Telerik.WinControls.UI.RadTextBox()
            CType(Me.ListView1, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.RadButton1, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.RadButton2, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.RadButton3, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.RadButton4, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.RadTextBox1, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.RadTextBox2, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.SuspendLayout()
            '
            'ListView1
            '
            Me.ListView1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                Or System.Windows.Forms.AnchorStyles.Left) _
                Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
            ListViewDetailColumn1.HeaderText = "Column 0"
            ListViewDetailColumn2.HeaderText = "Column 1"
            ListViewDetailColumn3.HeaderText = "Column 2"
            ListViewDetailColumn4.HeaderText = "Column 3"
            ListViewDetailColumn5.HeaderText = "Column 4"
            ListViewDetailColumn6.HeaderText = "Column 5"
            ListViewDetailColumn7.HeaderText = "Column 6"
            ListViewDetailColumn8.HeaderText = "Column 7"
            ListViewDetailColumn9.HeaderText = "Column 8"
            ListViewDetailColumn10.HeaderText = "Column 9"
            Me.ListView1.Columns.AddRange(New Telerik.WinControls.UI.ListViewDetailColumn() {ListViewDetailColumn1, ListViewDetailColumn2, ListViewDetailColumn3, ListViewDetailColumn4, ListViewDetailColumn5, ListViewDetailColumn6, ListViewDetailColumn7, ListViewDetailColumn8, ListViewDetailColumn9, ListViewDetailColumn10})
            Me.ListView1.GroupItemSize = New System.Drawing.Size(200, 20)
            Me.ListView1.ItemSize = New System.Drawing.Size(200, 20)
            Me.ListView1.ItemSpacing = -1
            Me.ListView1.Location = New System.Drawing.Point(49, 67)
            Me.ListView1.Name = "ListView1"
            Me.ListView1.Size = New System.Drawing.Size(782, 629)
            Me.ListView1.TabIndex = 1
            Me.ListView1.ViewType = Telerik.WinControls.UI.ListViewType.DetailsView
            '
            'ListView2
            '
            Me.ListView2.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader1, Me.ColumnHeader2, Me.ColumnHeader3, Me.ColumnHeader4, Me.ColumnHeader5, Me.ColumnHeader6, Me.ColumnHeader7, Me.ColumnHeader8, Me.ColumnHeader9, Me.ColumnHeader10})
            Me.ListView2.Location = New System.Drawing.Point(49, 67)
            Me.ListView2.Name = "ListView2"
            Me.ListView2.Size = New System.Drawing.Size(782, 629)
            Me.ListView2.TabIndex = 2
            Me.ListView2.UseCompatibleStateImageBehavior = False
            Me.ListView2.View = System.Windows.Forms.View.Details
            '
            'RadButton1
            '
            Me.RadButton1.Location = New System.Drawing.Point(49, 37)
            Me.RadButton1.Name = "RadButton1"
            Me.RadButton1.Size = New System.Drawing.Size(130, 24)
            Me.RadButton1.TabIndex = 3
            Me.RadButton1.Text = "RadButton1"
            '
            'RadButton2
            '
            Me.RadButton2.Location = New System.Drawing.Point(185, 37)
            Me.RadButton2.Name = "RadButton2"
            Me.RadButton2.Size = New System.Drawing.Size(130, 24)
            Me.RadButton2.TabIndex = 3
            Me.RadButton2.Text = "RadButton2"
            '
            'RadButton3
            '
            Me.RadButton3.Location = New System.Drawing.Point(353, 12)
            Me.RadButton3.Name = "RadButton3"
            Me.RadButton3.Size = New System.Drawing.Size(130, 24)
            Me.RadButton3.TabIndex = 4
            Me.RadButton3.Text = "RadButton3"
            '
            'RadButton4
            '
            Me.RadButton4.Location = New System.Drawing.Point(489, 12)
            Me.RadButton4.Name = "RadButton4"
            Me.RadButton4.Size = New System.Drawing.Size(130, 24)
            Me.RadButton4.TabIndex = 4
            Me.RadButton4.Text = "RadButton4"
            '
            'RadTextBox1
            '
            Me.RadTextBox1.Location = New System.Drawing.Point(353, 37)
            Me.RadTextBox1.Name = "RadTextBox1"
            Me.RadTextBox1.Size = New System.Drawing.Size(100, 20)
            Me.RadTextBox1.TabIndex = 5
            Me.RadTextBox1.TabStop = False
            Me.RadTextBox1.Text = "65"
            '
            'RadTextBox2
            '
            Me.RadTextBox2.Location = New System.Drawing.Point(489, 37)
            Me.RadTextBox2.Name = "RadTextBox2"
            Me.RadTextBox2.Size = New System.Drawing.Size(100, 20)
            Me.RadTextBox2.TabIndex = 5
            Me.RadTextBox2.TabStop = False
            Me.RadTextBox2.Text = "1"
            '
            'Form3
            '
            Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
            Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
            Me.ClientSize = New System.Drawing.Size(880, 724)
            Me.Controls.Add(Me.RadTextBox2)
            Me.Controls.Add(Me.RadTextBox1)
            Me.Controls.Add(Me.RadButton4)
            Me.Controls.Add(Me.RadButton3)
            Me.Controls.Add(Me.RadButton2)
            Me.Controls.Add(Me.RadButton1)
            Me.Controls.Add(Me.ListView2)
            Me.Controls.Add(Me.ListView1)
            Me.Name = "Form3"
            Me.Text = "Form3"
            CType(Me.ListView1, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.RadButton1, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.RadButton2, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.RadButton3, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.RadButton4, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.RadTextBox1, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.RadTextBox2, System.ComponentModel.ISupportInitialize).EndInit()
            Me.ResumeLayout(False)
            Me.PerformLayout()
      
        End Sub
        Private WithEvents ListView1 As Telerik.WinControls.UI.RadListView
        Friend WithEvents ListView2 As System.Windows.Forms.ListView
        Friend WithEvents RadButton1 As Telerik.WinControls.UI.RadButton
        Friend WithEvents RadButton2 As Telerik.WinControls.UI.RadButton
        Friend WithEvents ColumnHeader1 As System.Windows.Forms.ColumnHeader
        Friend WithEvents ColumnHeader2 As System.Windows.Forms.ColumnHeader
        Friend WithEvents ColumnHeader3 As System.Windows.Forms.ColumnHeader
        Friend WithEvents ColumnHeader4 As System.Windows.Forms.ColumnHeader
        Friend WithEvents ColumnHeader5 As System.Windows.Forms.ColumnHeader
        Friend WithEvents ColumnHeader6 As System.Windows.Forms.ColumnHeader
        Friend WithEvents ColumnHeader7 As System.Windows.Forms.ColumnHeader
        Friend WithEvents ColumnHeader8 As System.Windows.Forms.ColumnHeader
        Friend WithEvents ColumnHeader9 As System.Windows.Forms.ColumnHeader
        Friend WithEvents ColumnHeader10 As System.Windows.Forms.ColumnHeader
        Friend WithEvents RadButton3 As Telerik.WinControls.UI.RadButton
        Friend WithEvents RadButton4 As Telerik.WinControls.UI.RadButton
        Friend WithEvents RadTextBox1 As Telerik.WinControls.UI.RadTextBox
        Friend WithEvents RadTextBox2 As Telerik.WinControls.UI.RadTextBox
        Dim list As New List(Of String())
      
        Private Sub Form3_Load(sender As Object, e As System.EventArgs) Handles Me.Load
            For i = 0 To 300
                list.Add({"one " + i.ToString,
                          "two " + i.ToString,
                          "three " + i.ToString,
                          "four " + i.ToString,
                          "five " + i.ToString,
                          "six " + i.ToString,
                          "seven " + i.ToString,
                          "eight " + i.ToString,
                          "nine " + i.ToString,
                          "ten " + i.ToString})
            Next
        End Sub
      
        Private Sub RadButton1_Click(sender As System.Object, e As System.EventArgs) Handles RadButton1.Click
            ListView1.BringToFront()
            ListView1.Items.Clear()
            time = New Stopwatch()
            For Each i In list
                Dim li As New ListViewDataItem(i(0), i.ToArray())
                time.Start()
                ListView1.Items.Add(li)
                time.Stop()
            Next
            msg()
        End Sub
      
        Private Sub RadButton2_Click(sender As System.Object, e As System.EventArgs) Handles RadButton2.Click
            ListView2.BringToFront()
            ListView2.Items.Clear()
            time = New Stopwatch()
            For Each i In list
                Dim li As New ListViewItem(i(0))
                li.SubItems.AddRange(i.Skip(1).ToArray())
                time.Start()
                ListView2.Items.Add(li)
                time.Stop()
            Next
            msg()
        End Sub
      
        Dim time As Stopwatch
        Private Sub RadButton3_Click(sender As System.Object, e As System.EventArgs) Handles RadButton3.Click
            ListView1.BringToFront()
            ListView1.Items.Clear()
            Dim wait = CInt(RadTextBox1.Text)
            time = New Stopwatch()
            Threading.Tasks.Task.Factory.StartNew(
                Sub()
                    Dim last = list.Last()
                    For Each i In list
                        Dim ii = i
                        Dim li As New ListViewDataItem(i(0), i.ToArray())
                        Threading.Thread.Sleep(wait)
                        Me.BeginInvoke(
                            Sub()
                                time.Start()
                                ListView1.Items.Add(li)
                                time.Stop()
                                If ii Is last Then msg()
                            End Sub)
                    Next
                End Sub)
        End Sub
      
        Sub msg()
            MsgBox("Total is " + time.ElapsedMilliseconds.ToString)
        End Sub
      
        Private Sub RadButton4_Click(sender As System.Object, e As System.EventArgs) Handles RadButton4.Click
            ListView2.BringToFront()
            ListView2.Items.Clear()
            time = New Stopwatch()
            Dim wait = CInt(RadTextBox2.Text)
            Threading.Tasks.Task.Factory.StartNew(
                Sub()
                    Dim last = list.Last()
                    For Each i In list
                        Dim ii = i
                        Dim li As New ListViewItem(i(0))
                        li.SubItems.AddRange(i.Skip(1).ToArray())
                        Threading.Thread.Sleep(wait)
                        Me.BeginInvoke(
                            Sub()
                                time.Start()
                                ListView2.Items.Add(li)
                                time.Stop()
                                If ii Is last Then msg()
                            End Sub)
                    Next
                End Sub)
        End Sub
     End Class


    My experience with .Net is 7 years. My experience with Rad is about 2 weeks.

    • OS version and applied service packs

    Microsoft Windows Server 2003, Standard Edition, Service Pack 2

    • Regional and language settings, if different from En-US

    English (Australia)

    • .NET version (.NET2, .NET3, .NET3.5)

    .NET 4.0.30319 SP1Rel, Visual Studio 2010 Version 10.0.40219.1 SP1Rel

    • Exact version of the Telerik product 

    Runtime Version v2.0.50727, Version 2011.2.11.831

  2. Answer
    Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 27 Oct 2011 Link to this post

    Hello Clive,

    Thank you for contacting us.

    Adding items to RadListView at run-time causes layout operations which are fairly heavy. Therefore, when you are adding more items at run-time, you should use the BeginUpdate/EndUpdate methods of the Items collection. This should significantly improve performance in unbound mode.

    Please try the following code:
    Private Sub RadButton1_Click(sender As System.Object, e As System.EventArgs) Handles RadButton1.Click
        ListView1.BringToFront()
        ListView1.Items.Clear()
        ListView1.Items.BeginUpdate()
        time = New Stopwatch()
        For Each i In list
            Dim li As New ListViewDataItem(i(0), i.ToArray())
            time.Start()
            ListView1.Items.Add(li)
            time.Stop()
        Next
        ListView1.Items.EndUpdate()
        msg()
    End Sub

    As to using thread to improve performance, our controls are not thread safe and there might be  unexpected results.

    I hope this is useful. Should you have any additional questions, do not hesitate to ask.

    Kind regards,
    Ivan Todorov
    the Telerik team

    Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Clive
    Clive avatar
    12 posts
    Member since:
    Sep 2011

    Posted 30 Oct 2011 Link to this post

    Hi Ivan,

    Thanks for the reply, that worked very well. Funnily enough the begin update code was littered throughout our existing code and timers were all in place to beginupdate and endupdate every 300 milliseconds. The problem turned out to be I had not translated it to telerik way of coding properly.

    It would be good for you to provide conversion guides from .NET controls to Telerik controls. I was incorrectly using your BeginInit method, i.e. we had the following originally on our System.Windows.Forms.ListView inherited list view:

    Protected Shadows Sub BeginUpdate()
        If Not (Me.IsDisposed OrElse Me.Disposing) Then
            If ThreadControl.IsMainThread Then
                MyBase.BeginUpdate()
            Else
                Me.Invoke(New ThreadStart(AddressOf MyBase.BeginUpdate), Nothing)
            End If
        End If
    End Sub
    Protected Shadows Sub EndUpdate()
        If Not (Me.IsDisposed OrElse Me.Disposing) Then
            If ThreadControl.IsMainThread Then
                MyBase.EndUpdate()
            Else
                ThreadedUIInvoke(Me, New EndUpdateDelegate(AddressOf EndUpdate), Nothing)
                'Me.Invoke(New ThreadStart(AddressOf MyBase.EndUpdate), Nothing)
            End If
        End If
    End Sub

    With your assistance I changed it from my initial guess of BeginInit, to Items.BeginUpdate

    Public Shadows Sub BeginUpdate()
        If Not (Me.IsDisposed OrElse Me.Disposing) Then
            If ThreadControl.IsMainThread Then
                MyBase.Items.BeginUpdate() 'MyBase.BeginInit()
            Else
                ThreadedUIInvoke(Me, New action(AddressOf BeginUpdate), Nothing)
            End If
        End If
    End Sub
    Public Shadows Sub EndUpdate()
        If Not (Me.IsDisposed OrElse Me.Disposing) Then
            If ThreadControl.IsMainThread Then
                MyBase.Items.EndUpdate() 'MyBase.EndInit()
            Else
                ThreadedUIInvoke(Me, Sub() EndUpdate())
                'Me.Invoke(New ThreadStart(AddressOf MyBase.EndUpdate), Nothing)
            End If
        End If
    End Sub
  5. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 02 Nov 2011 Link to this post

    Hi Clive,

    I am glad that you have this sorted out.

    In fact, the BeginInit method of the controls and the BeginUpdate method of the Items collection of RadListView are not equivalent so they should not be just "converted" one into another. However, we surely need to improve the documentation for these methods and we also might expose them directly to the RadListView control.

    Thank you for your feedback. I have updated your Telerik points accordingly.

    In case you have any further questions, do not hesitate to contact us.

    All the best,
    Ivan Todorov
    the Telerik team

    Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

  6. RR
    RR avatar
    2 posts
    Member since:
    Jan 2012

    Posted 19 Jan 2012 Link to this post

    Hi,

    What are the best practices when binding a DataSource (ex: DataTable) to a ListVIew or DropDownList.

    Following is the Sample Code:

    objRADListView.ValueMember = strValueField
    objRADListView.DisplayMember = strDisplayField
    objRADListView.DataSource = dtDataSource

    Thanks.
  7. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 24 Jan 2012 Link to this post

    Hi,

    I am not sure that I fully understand what you want to achieve, however the code you have posted is all you need to do in order to bind RadListView to a DataTable and also, this is the best way to do so.

    Please, could you elaborate a bit more and describe in detail what you want to achieve. I will be glad to help further.

    All the best,
    Ivan Todorov
    the Telerik team

    SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).

Back to Top
UI for WinForms is Visual Studio 2017 Ready