tags:

views:

130

answers:

1

Hi Freinds, Here I just wants to have checkbox in my listview header. and i wrote the below code for that, can anyone help me out here to enable the check-box .

Now I could only be able to see the checkbox- not to click on it. Does anyone has any idea on this , can it be handled by listView3_ColumnClick event..?? Thanks in advance.

private void listView3_DrawColumnHeader_1(object sender, DrawListViewColumnHeaderEventArgs e) 
    {

        TextFormatFlags flags = TextFormatFlags.LeftAndRightPadding;
        e.DrawBackground();

        //CheckBoxRenderer.DrawCheckBox(e.Graphics, ClientRectangle.Location, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal);
        CheckBoxRenderer.DrawCheckBox(e.Graphics, ClientRectangle.Location, TextRectangle, "", this.Font, TextFormatFlags.HorizontalCenter, clicked, state);

        e.DrawText(flags);
    }
A: 

I think I have got that

private void listView_ColumnClick(object sender, ColumnClickEventArgs e)
    {
        if (!clicked)
        {
            clicked = true;
            state = CheckBoxState.CheckedPressed;  

            foreach (ListViewItem item in listView.Items)
            {
                item.Checked = true;
            }

            Invalidate();
        }
        else
        {
            clicked = false;
            state = CheckBoxState.UncheckedNormal;
            Invalidate();

            foreach (ListViewItem item in listView.Items)
            {
                item.Checked = false;
            }
        }           
    }

wheres state => private CheckBoxState state = CheckBoxState.UncheckedNormal;

Andy