This is a migrated thread and some comments may be shown as answers.

Saving and restoring Listview columns settings

5 Answers 480 Views
ListView
This is a migrated thread and some comments may be shown as answers.
pierre-jean
Top achievements
Rank 1
Veteran
Iron
pierre-jean asked on 19 Jan 2014, 12:32 PM
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

5 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 22 Jan 2014, 04:50 PM
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 >>
0
pierre-jean
Top achievements
Rank 1
Veteran
Iron
answered on 31 Jan 2014, 06:45 PM
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
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 05 Feb 2014, 12:17 PM
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 >>
0
Brandon
Top achievements
Rank 1
answered on 24 Jan 2019, 07:03 PM

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?

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 28 Jan 2019, 12:33 PM
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.
Tags
ListView
Asked by
pierre-jean
Top achievements
Rank 1
Veteran
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
pierre-jean
Top achievements
Rank 1
Veteran
Iron
Brandon
Top achievements
Rank 1
Share this question
or