listview columnorder setting /retrieving ??

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sagaert Johan

    #1

    listview columnorder setting /retrieving ??

    Hi

    I have set the columreorder to true

    Is there a way to get/set the current columnorder, so i can restore the
    order from a saved setting ?


    Johan


  • Theo Yaung [Microsoft]

    #2
    RE: listview columnorder setting /retrieving ??

    Hi Johan,

    The following should work similar to your needs. By storing arrays of
    ColumnHeaders, you're actually getting references to the same ColumnHeader
    objects that are currently in your ListView. Thus beware, if something in
    the ColumnHeader object changes (say, the Text), then it'll change for all
    the arrays that you capture. The only specific part of getting and
    settings these arrays are that they capture the ordering of the particular
    columns. If you wish to capture the exact state, then you'll need to copy
    the ColumnHeader objects too.

    Notice, for the SetColumnOrder( ) method, BeginUpdate() and EndUpdate() are
    called to ensure that clearing the columns and adding the columns get
    updated all at once for the end user, instead of the user being able to
    "see" the intermediate zero-column state.

    Do you have any further questions?

    using System.Windows. Forms;
    using ColumnHeaderCol lection =
    System.Windows. Forms.ListView. ColumnHeaderCol lection;
    ...
    public ColumnHeader[] GetColumnOrder( ListView lView) {
    ColumnHeaderCol lection columns = lView.Columns;
    int count = columns.Count;
    ColumnHeader[] arr = new ColumnHeader[count];
    for(int i = 0; i < count; i++) {
    arr[i] = columns[i];
    }
    return arr;
    }

    public void SetColumnOrder( ListView lView, ColumnHeader[] arr) {
    ColumnHeaderCol lection columns = lView.Columns;
    lView.BeginUpda te();
    columns.Clear() ;
    columns.AddRang e(arr);
    lView.EndUpdate ();
    }
    ...

    Hope this helps,

    Theo Yaung
    Software Design Engineer
    Visual Studio .NET Updates / Sustained Engineering
    Microsoft Corp.

    This posting is provided "AS IS" with no warranties, and confers no rights.
    --------------------[color=blue]
    >Reply-To: "Sagaert Johan" <sagaert_j@hotm ail.com>
    >From: "Sagaert Johan" <sagaert_j@hotm ail.com>
    >Subject: listview columnorder setting /retrieving ??
    >Date: Sun, 26 Oct 2003 11:02:33 +0100
    >
    >Hi
    >
    >I have set the columreorder to true
    >
    >Is there a way to get/set the current columnorder, so i can restore the
    >order from a saved setting ?
    >
    >
    >Johan
    >[/color]
    --
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of included script samples are subject to the terms specified at
    http://www.microsoft.com/info/cpyright.htm

    Note: For the benefit of the community-at-large, all responses to this
    message are best directed to the newsgroup/thread from which they
    originated.

    Comment

    • Sagaert Johan

      #3
      Re: listview columnorder setting /retrieving ??

      Thanks that will do the job !

      "Theo Yaung [Microsoft]" <theo_from_visu al_studio@onlin e.microsoft.com >
      wrote in message news:KtaNaTNnDH A.1548@cpmsftng xa06.phx.gbl...[color=blue]
      > Hi Johan,
      >
      > The following should work similar to your needs. By storing arrays of
      > ColumnHeaders, you're actually getting references to the same ColumnHeader
      > objects that are currently in your ListView. Thus beware, if something in
      > the ColumnHeader object changes (say, the Text), then it'll change for all
      > the arrays that you capture. The only specific part of getting and
      > settings these arrays are that they capture the ordering of the particular
      > columns. If you wish to capture the exact state, then you'll need to copy
      > the ColumnHeader objects too.
      >
      > Notice, for the SetColumnOrder( ) method, BeginUpdate() and EndUpdate() are
      > called to ensure that clearing the columns and adding the columns get
      > updated all at once for the end user, instead of the user being able to
      > "see" the intermediate zero-column state.
      >
      > Do you have any further questions?
      >
      > using System.Windows. Forms;
      > using ColumnHeaderCol lection =
      > System.Windows. Forms.ListView. ColumnHeaderCol lection;
      > ...
      > public ColumnHeader[] GetColumnOrder( ListView lView) {
      > ColumnHeaderCol lection columns = lView.Columns;
      > int count = columns.Count;
      > ColumnHeader[] arr = new ColumnHeader[count];
      > for(int i = 0; i < count; i++) {
      > arr[i] = columns[i];
      > }
      > return arr;
      > }
      >
      > public void SetColumnOrder( ListView lView, ColumnHeader[] arr) {
      > ColumnHeaderCol lection columns = lView.Columns;
      > lView.BeginUpda te();
      > columns.Clear() ;
      > columns.AddRang e(arr);
      > lView.EndUpdate ();
      > }
      > ...
      >
      > Hope this helps,
      >
      > Theo Yaung
      > Software Design Engineer
      > Visual Studio .NET Updates / Sustained Engineering
      > Microsoft Corp.
      >
      > This posting is provided "AS IS" with no warranties, and confers no[/color]
      rights.[color=blue]
      > --------------------[color=green]
      > >Reply-To: "Sagaert Johan" <sagaert_j@hotm ail.com>
      > >From: "Sagaert Johan" <sagaert_j@hotm ail.com>
      > >Subject: listview columnorder setting /retrieving ??
      > >Date: Sun, 26 Oct 2003 11:02:33 +0100
      > >
      > >Hi
      > >
      > >I have set the columreorder to true
      > >
      > >Is there a way to get/set the current columnorder, so i can restore the
      > >order from a saved setting ?
      > >
      > >
      > >Johan
      > >[/color]
      > --
      > This posting is provided "AS IS" with no warranties, and confers no[/color]
      rights.[color=blue]
      > Use of included script samples are subject to the terms specified at
      > http://www.microsoft.com/info/cpyright.htm
      >
      > Note: For the benefit of the community-at-large, all responses to this
      > message are best directed to the newsgroup/thread from which they
      > originated.
      >[/color]


      Comment

      Working...