Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] List view index from point #53

Open
Hi-ImKyle opened this issue Jan 6, 2021 · 1 comment
Open

[Feature] List view index from point #53

Hi-ImKyle opened this issue Jan 6, 2021 · 1 comment

Comments

@Hi-ImKyle
Copy link

As it currently sits the dark list view control has no IndexFromPoint method, I feel as though it would be a good addition and so I'm kindly asking for it to be implemented. I would do it myself but I am not confident enough with something like that.

Thanks.

@Dutchs
Copy link

Dutchs commented Feb 10, 2022

It's basically what DarkListView.OnMouseDown() does, minus selection:

public int IndexFromPoint(Point p)
{
    int result = -1;

    if (Items.Count != 0)
    {
        var pos = new Point(p.X + Viewport.Left, p.Y + Viewport.Top);

        var range = ItemIndexesInView().ToList();

        var top = range.Min();
        var bottom = range.Max();
        var width = Math.Max(ContentSize.Width, Viewport.Width);

        for (var i = top; i <= bottom; i++)
        {
            var rect = new Rectangle(0, i * ItemHeight, width, ItemHeight);

            if (rect.Contains(pos))
            {
                result = i;
                break;
            }
        }
    }

    return result;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants