Jaex
Jaex

Reputation: 4304

How to remove 1px space between ListViewItem

In ListView between ListViewItems have 1px space and it causing me to miss click between them frequently. This only happens if ListViewItem in ListViewGroup.

I recorded video to show it: https://jaex.getsharex.com/2022/06/pBBk1aXmD6.mp4

In video I can click between two items which makes ListViewItem unselected. This problem not happens if I don't use ListViewGroup.

Upvotes: 0

Views: 211

Answers (3)

Jaex
Jaex

Reputation: 4304

I'm using this workaround now:

    private void lvMain_MouseUp(object sender, MouseEventArgs e)
    {
        if (lvMain.SelectedItems.Count == 0 && (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right))
        {
            ListViewItem lvi = lvMain.GetItemAt(e.X, e.Y);

            if (lvi == null)
            {
                // Workaround for 1px space between items
                lvi = lvMain.GetItemAt(e.X, e.Y - 1);
            }

            if (lvi != null)
            {
                lvi.Selected = true;
            }
        }
    }

If clicked to empty space between two items then checking one pixel top of this position and if item exist in this position then selecting it.

Upvotes: 1

Shell
Shell

Reputation: 6849

There is no such property to assign value like that. But, you can customize your list item by drawing each ListViewItem in DrawItem event. you need to assign OwenerDraw event first for that.

Check out the example given in msdn

Upvotes: 0

fishmong3r
fishmong3r

Reputation: 1434

As far as I know there is no such property to set. Maybe you could draw the ListViewGroup yourself. Or try to solve it without group, which is apparently inceonvenient for you though.

Or store the selection in a variable, create a background worker/click event to check button clicks on ListViewGroup, and if nothing is selected set it back to the previous.

Upvotes: 0

Related Questions