question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for tasks to ListViewGroup

See original GitHub issue
  • You can set the LVGF_TASK flag on mask and set pszTask to a valid string and cchTask to the length of the string

Proposed API

This would add the following APIs to ListView and ListViewGroup. I modelled these after the ColumnClick event args/handler/method

public delegate void GroupLinkClickEventHandler(object sender, GroupLinkClickEventArgs e);
public class GroupLinkClickEventArgs : EventArgs
{
    public GroupLinkClickEventArgs(int column) { }

    public int GroupLink { get; }
}
public class ListView
{
    ...
    public event GroupLinkClickEventHandler GroupLinkClick { add; remove; }
    protected void OnGroupLinkClick(GroupEventArgs e) { }
    ...
}
public class ListViewGroup
{
    ...
    public string Task { get; set; }
    ...
}

Example

var listView = new ListView();
var group = new ListViewGroup
{
    Task = "Task"
};
listView.Groups.Add(group);
listView.GroupLinkClick += (sender, e) => MessageBox.Show("Link Clicked");

E.g. Screen Recording 2020-01-04 at 07 01 pm

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

4reactions
hughbecommented, May 14, 2020

In my local implementation I went with the LVN_LINKCLICK. Although this would add more structs to the internal interop, this is no harm - they’re not exposed and relatively simple.

I think making the distinction between the header and the task itself is important so I think LVN_LINKCLICK is the way to go

I agree

Example LVN_CLICKED in WndProc


case (int)User32.WindowMessage.WM_REFLECT_NOTIFY:
    User32.NMHDR* nmhdr = (User32.NMHDR*)m.LParam;
    switch (nmhdr->code)
    {
        case (int)LVN.LINKCLICK:
            NMLVLINK* link = (NMLVLINK*)m.LParam;
            string task = "Clicked";
            var group = new LVGROUPW
            {
                cbSize = (uint)sizeof(LVGROUPW),
                mask = LVGF.TASK,
                cchTask = (uint)task.Length
            };
            fixed (char* pTask = "Clicked")
            {
                group.pszTask = pTask;
                User32.SendMessageW(Handle, (User32.WindowMessage)LVM.SETGROUPINFO, (IntPtr)link->iSubItem, ref group);
                MessageBox.Show("Link Clicked");
            }
            break;
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

internal static partial class Interop
{
    internal static partial class ComCtl32
    {
        public struct NMLVLINK
        {
            public User32.NMHDR nmhdr;
            public LITEM link;
            public int iItem;
            public int iSubItem;
        }
    }
}
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

internal static partial class Interop
{
    internal static partial class ComCtl32
    {
        public unsafe struct LITEM
        {
            private const int MAX_LINKID_TEXT = 48;
            private const int L_MAX_URL_LENGTH = 2048 + 32 + 3;

            public LIF mask;
            public int iLink;
            public LIS state;
            public LIS stateMask;
            public fixed char szID[MAX_LINKID_TEXT];
            public fixed char szUrl[L_MAX_URL_LENGTH];
        }
    }
}
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;

internal static partial class Interop
{
    internal static partial class ComCtl32
    {
        [Flags]
        public enum LIF : uint
        {
            ITEMINDEX = 0x00000001,
            STATE = 0x00000002,
            ITEMID = 0x00000004,
            URL = 0x00000008,
        }
    }
}
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;

internal static partial class Interop
{
    internal static partial class ComCtl32
    {
        [Flags]
        public enum LIS : uint
        {
            FOCUSED = 0x00000001,
            ENABLED = 0x00000002,
            VISITED = 0x00000004,
            HOTTRACK = 0x00000008,
            DEFAULTCOLORS = 0x00000010,
        }
    }
}
2reactions
JeremyKuhnecommented, May 14, 2020

I think making the distinction between the header and the task itself is important so I think LVN_LINKCLICK is the way to go

I agree as well

Read more comments on GitHub >

github_iconTop Results From Across the Web

ListViewGroup Class (System.Windows.Forms)
ListView groups help your users find the items they are looking for by separating the items into useful categories. You can create whatever...
Read more >
ListViewGroup.TaskLink Property (System.Windows.Forms)
The name of the task link displayed in the group header.
Read more >
c# - Empty ListViewGroup is not shown in ListView
AddGroup , adding an item you can use of the listView.AddItem methods. This is opposed to listView.Items.Add and listView.Groups.Add methods.
Read more >
Adding groups to ListView depending on the data in a list
I have written simple code which loops through a list object and create groups in ListView depending on the data in the list....
Read more >
Create ListviewGroups Dynamically - PowerShell
There is a way to create dynamic groups ? In this example I have 2 computers, each line shows the disk partition of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found