Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Checkbox on the header of a Listview

Checkbox on the header of a Listview

Scheduled Pinned Locked Moved C#
graphicshelptutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Natural_Demon
    wrote on last edited by
    #1

    i have made this piece of code, to a checkbox on the header: wel not realy on the headr, but situated there. (class ColumnHeader doesn't provide much, like for example: OnpaintEvent. but i need some help with the special effects. if you hoover the mouse over the header, the mousehover effect of the header hides the checkbox, bringing it to the background. i would like to have the checkbox ontop @ all time. using windows 7.

    using System;
    using System.Drawing;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;
    
    namespace Listview_Colum_header_checkbox
    {
        class CCehckBox : CheckBox
        {
            public CCehckBox()
            {
                Width = 14;
                Height = 14;
                //a
                //ValidationConstraints.Visible
                //AutoValidate.EnablePreventFocusChange;
            }
    
            protected override void OnPaint(PaintEventArgs pevent)
            {
                Invalidate();
                base.OnPaint(pevent);
            }
        }
    
        class CListViewHeader : ColumnHeader
        {
            void CListViewHeader()
            {
            }
        }
    
        class CListview : ListView
        {
            private readonly CCehckBox _cCehckBox = new CCehckBox();
            private readonly ColumnHeader _header1 = new ColumnHeader();
            private readonly ColumnHeader _header2 = new ColumnHeader();
            private readonly ColumnHeader _header3 = new ColumnHeader();
    
            #region  PInvoke Declarations
    
            [DllImport("user32")]
            private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
    
            #endregion
    
            public CListview()
            {
                View = View.Details;
    
                _header1 = Columns.Add("Name");
                _header1.Width = (Location.X + 5) + 6;
                _header1.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
                _header1.Name = "CheckBox";
                _header1.DisplayIndex = 0;
    
                _header2 = Columns.Add("bah");
                _header2.Width = (Width - 20) - 50;
    
                _header3 = Columns.Add("boh");
                _header3.Width = 50;
    
                var wijd = _cCehckBox.Width;
                var hoog = _cCehckBox.Height;
                _cCehckBox.Location = new Point(Location.X+ 5, Location.Y + 5);
            }
    
    
            protected override void OnColumnWidthChanged(ColumnWidthChangedEventArgs e)
            {
                
                if(e.ColumnIndex == 0)
                {
                    //MessageBox.Show(e.ColumnIndex.ToString());
    
    R 1 Reply Last reply
    0
    • N Natural_Demon

      i have made this piece of code, to a checkbox on the header: wel not realy on the headr, but situated there. (class ColumnHeader doesn't provide much, like for example: OnpaintEvent. but i need some help with the special effects. if you hoover the mouse over the header, the mousehover effect of the header hides the checkbox, bringing it to the background. i would like to have the checkbox ontop @ all time. using windows 7.

      using System;
      using System.Drawing;
      using System.Runtime.InteropServices;
      using System.Windows.Forms;
      
      namespace Listview_Colum_header_checkbox
      {
          class CCehckBox : CheckBox
          {
              public CCehckBox()
              {
                  Width = 14;
                  Height = 14;
                  //a
                  //ValidationConstraints.Visible
                  //AutoValidate.EnablePreventFocusChange;
              }
      
              protected override void OnPaint(PaintEventArgs pevent)
              {
                  Invalidate();
                  base.OnPaint(pevent);
              }
          }
      
          class CListViewHeader : ColumnHeader
          {
              void CListViewHeader()
              {
              }
          }
      
          class CListview : ListView
          {
              private readonly CCehckBox _cCehckBox = new CCehckBox();
              private readonly ColumnHeader _header1 = new ColumnHeader();
              private readonly ColumnHeader _header2 = new ColumnHeader();
              private readonly ColumnHeader _header3 = new ColumnHeader();
      
              #region  PInvoke Declarations
      
              [DllImport("user32")]
              private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
      
              #endregion
      
              public CListview()
              {
                  View = View.Details;
      
                  _header1 = Columns.Add("Name");
                  _header1.Width = (Location.X + 5) + 6;
                  _header1.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
                  _header1.Name = "CheckBox";
                  _header1.DisplayIndex = 0;
      
                  _header2 = Columns.Add("bah");
                  _header2.Width = (Width - 20) - 50;
      
                  _header3 = Columns.Add("boh");
                  _header3.Width = 50;
      
                  var wijd = _cCehckBox.Width;
                  var hoog = _cCehckBox.Height;
                  _cCehckBox.Location = new Point(Location.X+ 5, Location.Y + 5);
              }
      
      
              protected override void OnColumnWidthChanged(ColumnWidthChangedEventArgs e)
              {
                  
                  if(e.ColumnIndex == 0)
                  {
                      //MessageBox.Show(e.ColumnIndex.ToString());
      
      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #2

      Imho, your best bet would be to use a class derived from ColumnHeader[^]. /ravi

      My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

      N 1 Reply Last reply
      0
      • R Ravi Bhavnani

        Imho, your best bet would be to use a class derived from ColumnHeader[^]. /ravi

        My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

        N Offline
        N Offline
        Natural_Demon
        wrote on last edited by
        #3

        i tried that, but it doesn't look 'ColumnHeader' it provides me the nessesary properties to do this.

        Bad = knowing 2 much

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups