ListView column ordering

P

Pat Grever

I'm hosting a .NET Window Forms ListView control (in
Detail view) in an IE web page. The control is
configured to allow column reordering. The user can
click and drag a column header to move it, and this is
working perfectly. However, I cannot find any class
methods or properties that indicate the current column
ordering. I need this information to preserve the
settings across hits to the web page, and to do my own
drawing of the content of the control. Does anybody know
what the equivalent to the old Win32 message
LVM_GETCOLUMNORDERARRAY is when using the .NET classes?
 
Y

Ying-Shen Yu[MSFT]

Hi Pat,

..NET ListView control didn't expose this information, however we still can
get the order array by platform invoke. Here is a sample snippet for
getting the order, also set order array looks similiar to get order array,
basically you should only change the msgid to LVM_SETCOLUMNARRAY.

If my work around doesn't work for you , please be free to reply this
thread to let me know.
Thanks!

<code>
private void button1_Click(object sender, System.EventArgs e)
{
int[] order = getColumnOrder(listView1);
listBox1.Items.Clear();
foreach(int i in order)
{
listBox1.Items.Add(i.ToString());
}
}
private int[] getColumnOrder(ListView lv)
{
const int LVM_FIRST = 0x1000; // ListView messages
const int LVM_GETCOLUMNORDERARRAY = LVM_FIRST + 59;
const int LVM_SETCOLUMNORDERARRAY = LVM_FRIST + 58;
int[] orders = new int[listView1.Columns.Count];
int ret =
SendMessage(listView1.Handle,LVM_GETCOLUMNORDERARRAY,orders.Length,orders);
if (ret > 0)
return orders;
throw new Exception("Getorder failed");
}

[DllImport("user32.dll")]
private extern static int SendMessage(IntPtr hwnd, uint msg, int count,

[MarshalAs(UnmanagedType.LPArray,ArraySubType=UnmanagedType.I4),In,Out]int[]
orderArray);
</code>


Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending.
 
G

Guest

Thanks for the hint, but this does not really help me.
As I stated in my original message, I am trying to host
this control in IE.

The postback causes a transition from managed to
unmanaged code. This requires special .NET privileges
not normally granted to WEB sites. In order to use the
solution given, I would need to have ALL my customers
over the web reconfigure their .NET security to give my
site full trust. This is not a reasonable solution. Not
only is it a lot to expect a non-technical customer to
know how to do this, but just about any customer will
react negatively to needing to open a security hole this
big in on their machine.

It also seems silly for the control to support user draw
style if it does not expose the column order
information. How can someone possible draw the control
properly in detail mode if they cannot find out what
order the columns are in? If you are going to support
one, seems like you have to support the other.

Pat
 
P

Pat Grever

(sorry - originally sent this from anonymous)

Thanks for the hint, but this does not really help me.
As I stated in my original message, I am trying to host
this control in IE.

The postback causes a transition from managed to
unmanaged code. This requires special .NET privileges
not normally granted to WEB sites. In order to use the
solution given, I would need to have ALL my customers
over the web reconfigure their .NET security to give my
site full trust. This is not a reasonable solution. Not
only is it a lot to expect a non-technical customer to
know how to do this, but just about any customer will
react negatively to needing to open a security hole this
big in on their machine.

It also seems silly for the control to support user draw
style if it does not expose the column order
information. How can someone possible draw the control
properly in detail mode if they cannot find out what
order the columns are in? If you are going to support
one, seems like you have to support the other.

Pat
 
Y

Ying-Shen Yu[MSFT]

Hi Pat,

Thanks for your reply!
I fully understanding your feeling, I have forwarded your feedback to our
product group.We will try our best to make our product meet the customers'
needs.

For now, I think we still need use interop to do get the order array. If
this control is hosted in IE, it might have the pemission problem. As you
said, most end-users don't know how to config the security policy correctly
and if so there might be a security hole.

However, .NET we can assign pemission based on strong name. strong name is
based on the public/private asymmetric encryption mechanism. Without the
private key, noone can make an identical strong name assembly. So you are
safe to assign pemission based on the strong name. For more information
on Strong Name , you may refer to
<Strong Name Assemblies>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconstrong-namedassemblies.asp

Also, the config procedure is too complex for the end-user, you may write
command script to simplify this job, .NET Framework provides an cmd-line
tool the "CasPol.exe" to configure the pemissions. For more information on
this tool you may refer to
<Configuring Security Policy Using the Code Access Security Policy Tool
(Caspol.exe)>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconUsingCodeAccessSecurityPolicyToolCaspolexe.asp

If you have anything unclear abou this issue, please be free to reply this
thread to let me know!
Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending.
 
P

Pat Grever

Ying-Shen Yu,

Thank you for the information. This matches what I had
found previously. Unfortunately my product has a zero-
install requirement so even the strong encryption does
not help.

Thank you for trying. I hope the control eventually
exposes this functionality.

Pat
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top