Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show full row highlighting for a ListViewItem?

Tags:

.net

winforms

I've got a ListView and, for View = List, would like to have the list items fill up the entire width of the control. That is, when you click an item the whole row is highlighted.

I can't find any setting in the ListView or ListViewItem to control this behavior, and padding with spaces doesn't work very well because I cannot rely on the text being fixed-width.

Anyone know how to do it?

like image 428
Pat Avatar asked Feb 26 '23 18:02

Pat


1 Answers

You can bind the width of the ListViewItem to the width of the ListView :

...
    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
            <Setter Property="Width" Value="{Binding ActualWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListView}}}" />
        </Style>
    <ListView.ItemContainerStyle>
...


EDIT: you can set the ListView.FullRowSelect property to true

like image 157
Thomas Levesque Avatar answered Mar 01 '23 06:03

Thomas Levesque