Saving and restoring Listview columns settings

4 posts, 0 answers
  1. pierre-jean
    pierre-jean avatar
    22 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
    Admin
    Dess avatar
    1609 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. UI for WinForms is Visual Studio 2017 Ready
  4. pierre-jean
    pierre-jean avatar
    22 posts
    Member since:
    Apr 2011

    Posted 31 Jan 2014 in reply to Dess 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
  5. Dess
    Admin
    Dess avatar
    1609 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 >>
Back to Top