 |
|
 |
I downloaded the source code, Win 7, executed the project without changing anything and it throws an exception at the Marshl.StructureToPtr()
|
|
|
|
 |
|
 |
Sorry, I am running a 64-bit machine, just forced 32 bit and it worked.
|
|
|
|
 |
|
 |
Listview may get repaint issue when groups are collapsing or expanding with scrollbar presenting or disappearing. Tested on Win7.
A picture means everything.
http://hi.csdn.net/attachment/201105/27/1705918_1306468648h8Tc.jpg[^]
Follow up on 26/7/2011: API call SendMessage to force a redraw:
Public Property Let AllowRedraw(bRedraw As Boolean)
If m_hListView Then
Call SendMessage(m_hListView, WM_SETREDRAW, Abs(CLng(bRedraw)), 0&)
m_AllowRedraw = bRedraw
End If
End Property
modified on Tuesday, July 26, 2011 5:43 AM
|
|
|
|
 |
|
 |
I'd tried to do this exact same thing before, but never quite managed it. Your code showed me where I was going wrong. Cheers!
|
|
|
|
 |
|
|
 |
|
 |
- The strings in LVGROUP should be LPWStr, not LPTStr. Check the windows headers.
- Why write your own marshaling code when you can just declare LVGROUP as ref param.
- Group id: someone else already mentioned it.
- Design: collapsible/collapsed should be properties of the group, as in win32 api. Yes, the group and group collection can't be inherited, but there're ways around it, and they can be added to work with the designer as if the properties come from the groups.
- Other misc stuffs like the use of const literals, exception handling...
All these are rather trivial, and that's why the article level is beginner.
|
|
|
|
 |
|
 |
In your "Design" issue you mention ways to add the functionality to the class and/or designer, could you point me in the direction of some information or examples on how this might be accomplished. Thanks.
|
|
|
|
 |
|
 |
Trivial stuff for Vista only...
|
|
|
|
 |
|
 |
I wouldn't say this is trivial. Not many people understand how to use interop code or even that you can use interop code to change the behavior of the standard .NET winforms controls.
List view grouping is also supported on Windows XP and later, including Vista and Win7. Being able to collapse the groups is Vista and later.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
 |
|
|
 |
|
 |
I would like to do this same thing for VB.Net...is there any way to do that?
Thanks in advance!
|
|
|
|
 |
|
|
 |
|
 |
I had a similar problem while subclassing the listview control to catch LVN_LINKCLICK event. The fact is that ListView.WndProc catch the WM_LBUTTONUP event. So if you want to make it managed by the native control, you have to send it to DefWndProc first.
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
protected override void WndProc(ref Message m)
{
if(m.Msg == 0x202 /*WM_LBUTTONUP*/)
base.DefWndProc(ref m);
base.WndProc(ref m);
}
Regards,
François
|
|
|
|
 |
|
 |
For those wondering, here is the completed WndProc override to show the arrow and get the expand/collapse to work:
protected override void WndProc(ref Message m)
{
switch (m.Msg) {
case 0x1000 + 145:
// LVM_INSERTGROUP = LVM_FIRST + 145;
// Add the collapsible feature id needed
if (hasCollapsibleGroup) {
LVGROUP @group = (LVGROUP)Marshal.PtrToStructure(m.LParam, typeof(LVGROUP));
@group.state = (int)GroupState.COLLAPSIBLE;
// LVGS_COLLAPSIBLE
@group.mask = @group.mask ^ 4;
// LVGF_STATE
Marshal.StructureToPtr(@group, m.LParam, true);
}
base.WndProc(m);
break; // TODO: might not be correct. Was : Exit Select
break;
case 0x202:
//WM_LBUTTONUP
base.DefWndProc(m);
base.WndProc(m);
break; // TODO: might not be correct. Was : Exit Select
break;
default:
base.WndProc(m);
break; // TODO: might not be correct. Was : Exit Select
break;
}
}
However, I can't for the life of me figure out why I can't get the ExpandAll/Collapse all in this sample to work!!!!
It blows up on the following statement:
Marshal.StructureToPtr(@group, ip, true);
???????
The Doctor's In
Ron
|
|
|
|
 |
|
 |
what is hasCollapsibleGroup?
I don't see it set in your code, and in my version setting to either true or false i see no visible difference in the running.
|
|
|
|
 |
|
 |
The hasCollapsibleGroup is a property set at design time. This was an attempt to handle WinXp since WinXP does not support collabsilble groups.
|
|
|
|
 |
|
 |
Hi man, it doesn't work, i don't understand this lines:
// Add the collapsible feature id needed
if (hasCollapsibleGroup) {
wich id are you talking about, i know that the group state has id's but how do i use them or what?
thanks in advance...
|
|
|
|
 |
|
 |
Mcarmonar83,
There is a typo in the comment line (id should read if)..
//Add the collapsible feature if needed
The boolean variable, hasCollapsiblegroup, is a public property set at design time on the control itself.
Ron
The Doctor's In
|
|
|
|
 |
|
|
 |
|
 |
not working under xp, too bad because its a simple solution
|
|
|
|
 |
|
|
 |
|
 |
Only tested under Vista and win2k8
|
|
|
|
 |
|
 |
Hi Charju,
Nice work with this. Have you verified the fix for clicking on the right-side arrow as François suggested, and if so will you update the source code with that change? Double clicking works fine, but the arrows are more intuitive.
Thanks for a great contribution,
_Steve
|
|
|
|
 |
|
|
 |
|
 |
Source code added and a bug fixed in SendMessage func call,
|
|
|
|
 |