Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

listview Header check-box

Tags:

c#

listview

I'm having a windows form which contains listview control , where listView1.View = View.Details; and listView1.CheckBoxes = true;

then added a column with HeaderName as "FileName".

listView1.Columns.Add("File Name", 200, HorizontalAlignment.Left);

Here I would like to have check box in the Header of listview , ie FileName.

Can anyone help me with this.

Thanks in advance. andy

like image 536
Anees Avatar asked Dec 02 '22 06:12

Anees


1 Answers

A ListView header with a checkbox is not part of the standard ListView functionality. You'll need to customise the renderering to do this:

    listview.OwnerDraw = true


    private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
    {
        // Draw your custom checkbox control here
    }

    private void listView1_DrawItem(object sender, DrawListViewItemEventArgs e)
    {
        e.DrawDefault = true;
    }

    private void listView1_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
    {
        e.DrawDefault = true;
    }

You'll also have to add some click handlers for the header and manage the state of your checkboxes yourself.

like image 140
Matt Breckon Avatar answered Dec 26 '22 04:12

Matt Breckon