Saving and restoring Listview columns settings

6 posts, 0 answers
  1. pierre-jean
    pierre-jean avatar
    108 posts
    Member since:
    Apr 2011

    Posted 19 Jan 2014 Link to this post

    I need to save and then restore listview columns settings (mainly column width and column order) when the user changes these settings:
    1. How do I save and restore the columns width and order
    2. Which event can I use to trap a user's column width and/or order change

    I have not found a method like the save and restore layout of the radgridview ..

    Thanks in advance
    Pierre-Jean
  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3707 posts

    Posted 22 Jan 2014 Link to this post

    Hello Pierre-jean,

    Thank you for contacting Telerik Support.

    Our RadListView does not support save/load layout functionality similar to the one available for the RadGridView. However, you can handle the ListViewDetailColumn's width changes, by subscribing to the PropertyChanged event and using the following code:
    private void col_PropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        if (e.PropertyName=="Width")
        {
             
        }
    }

    As to the columns reordering, you can use the RadListView.Columns.CollectionChanged event in order to trace changes in columns order.

    I hope this information helps. Should you have further questions, I would be glad to help.

    Regards,
    Desislava
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. pierre-jean
    pierre-jean avatar
    108 posts
    Member since:
    Apr 2011

    Posted 31 Jan 2014 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Thanks with your help I managed to trap the events and write a save/restore function for the column widths.
    However I have not found a solution to save and restore the columns order, this is however not really important to my application.
    Regards
  4. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3707 posts

    Posted 05 Feb 2014 Link to this post

    Hello Pierre-Jean,

    Thank you for writing back.

    It is possible to handle when columns are being reordered as well via the ColumnDragDropService:
    this.radListView1.ViewType = Telerik.WinControls.UI.ListViewType.DetailsView;
     
    DetailListViewElement el = this.radListView1.ListViewElement.ViewElement as DetailListViewElement;
    if (el != null)
    {
        el.ColumnDragDropService.PreviewDragDrop += ColumnDragDropService_PreviewDragDrop;
    }

    private void ColumnDragDropService_PreviewDragDrop(object sender, RadDropEventArgs e)
    {
        DetailListViewHeaderCellElement target = e.HitTarget as DetailListViewHeaderCellElement;
        DetailListViewHeaderCellElement drag = e.DragInstance as DetailListViewHeaderCellElement;
        if (target != null && drag != null)
        {
            ListViewDetailColumn targetColumn = target.Data;
            ListViewDetailColumn dragColumn = drag.Data;
            int targetColumnIndex = this.radListView1.Columns.IndexOf(targetColumn.Name);
            int dragColumnIndex = this.radListView1.Columns.IndexOf(dragColumn.Name);
        }
    }

    Thus, you can implement the logic for saving columns order.

    Please do not hesitate to contact us if you have any additional questions.

    Regards,
    Desislava
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  5. Brandon
    Brandon avatar
    21 posts
    Member since:
    Jan 2019

    Posted 24 Jan 2019 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    I have tried using:

    Private Sub lvEquip_ColumnWidthChanged(sender As Object, e As PropertyChangedEventArgs)
        If e.PropertyName = "Width" Then
            Dim Ini As New IniFile(GetAppDataPath() & "\dat.ini")
            For I As Integer = 0 To lvEquip.Columns.Count - 1
                Ini.PutVar("Settings", "ColSize_Equip_" & I, lvEquip.Columns(I).Width)
                Settings.ColSize_Equip(I) = lvEquip.Columns(I).Width
            Next
        End If
    End Sub

     

    With:

    AddHandler lvEquip.Columns.PropertyChanged, AddressOf lvEquip_ColumnWidthChanged

     

    ^^ In the load event.  It does not capture when the width of a column is changed.  I set a breakpoint directly on [If e.PropertyName = "Width" Then] and it never gets hit.  What am I missing?

  6. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3707 posts

    Posted 28 Jan 2019 Link to this post

    Hello, Brandon,      

    If you want to detect when a column's width in RadListView is changed, it is necessary to iterate the Columns collection and subscribe to the PropertyChanged event for each ListViewDetailColumn:  

    For Each col As ListViewDetailColumn In Me.RadListView1.Columns
        AddHandler col.PropertyChanged, AddressOf col_PropertyChanged
    Next

    Private Sub col_PropertyChanged(sender As Object, e As System.ComponentModel.PropertyChangedEventArgs)
        Console.WriteLine(e.PropertyName)
    End Sub

    I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top