listview columnorder setting /retrieving ??

  • Thread starter Thread starter Sagaert Johan
  • Start date Start date
S

Sagaert Johan

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
 
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 ColumnHeaderCollection =
System.Windows.Forms.ListView.ColumnHeaderCollection;
...
public ColumnHeader[] GetColumnOrder(ListView lView) {
ColumnHeaderCollection columns = lView.Columns;
int count = columns.Count;
ColumnHeader[] arr = new ColumnHeader[count];
for(int i = 0; i < count; i++) {
arr = columns;
}
return arr;
}

public void SetColumnOrder(ListView lView, ColumnHeader[] arr) {
ColumnHeaderCollection columns = lView.Columns;
lView.BeginUpdate();
columns.Clear();
columns.AddRange(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.
--------------------
Reply-To: "Sagaert Johan" <[email protected]>
From: "Sagaert Johan" <[email protected]>
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
--
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.
 
Thanks that will do the job !

Theo Yaung said:
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 ColumnHeaderCollection =
System.Windows.Forms.ListView.ColumnHeaderCollection;
...
public ColumnHeader[] GetColumnOrder(ListView lView) {
ColumnHeaderCollection columns = lView.Columns;
int count = columns.Count;
ColumnHeader[] arr = new ColumnHeader[count];
for(int i = 0; i < count; i++) {
arr = columns;
}
return arr;
}

public void SetColumnOrder(ListView lView, ColumnHeader[] arr) {
ColumnHeaderCollection columns = lView.Columns;
lView.BeginUpdate();
columns.Clear();
columns.AddRange(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.
--------------------
Reply-To: "Sagaert Johan" <[email protected]>
From: "Sagaert Johan" <[email protected]>
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
--
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.
 
Back
Top