Results 1 to 2 of 2

Thread: header checkbox in datagrid view

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2007
    Location
    Karachi
    Posts
    551

    header checkbox in datagrid view

    hi to all

    I have follwoing code in desktop application ..


    Code:
     private void Form1_Load(object sender, EventArgs e)
            {
                this.dataGridView1.Visible = false;
                DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn();
    
               // column.HeaderText = "All";
               // c1.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
                column.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
                     
                column.Name = "Selected";
                //column.AutoSizeMode =
                this.dataGridView1.Columns.Add(column);
    
                 ckBox = new CheckBox();
    
                //Get the column header cell bounds
    
                Rectangle rect =
    
                    this.dataGridView1.GetCellDisplayRectangle(0, -1, true);
    
                ckBox.Size = new Size(18, 18);
    
                //Change the location of the CheckBox to make it stay on the header
    
                ckBox.Location = rect.Location;
    
                ckBox.CheckedChanged += new EventHandler(ckBox_CheckedChanged);
    
                //Add the CheckBox into the DataGridView
    
                this.dataGridView1.Controls.Add(ckBox);
    
    
                //DataGridViewAutoSizeColumnMode.DisplayedCells;
                //column.FlatStyle = FlatStyle.Standard;
                //column.ThreeState = false;
                //column.CellTemplate = new DataGridViewCheckBoxCell();
                //column.CellTemplate.Style.BackColor = Color.Beige;
    
               // dataGridView1.Columns.Insert(0, column); // This is to be a checkbox column
    
                //Rectangle rect = dataGridView1.GetCellDisplayRectangle(0, -1, true);
                //// set checkbox header to center of header cell. +1 pixel to position correctly.
                //rect.X = rect.Location.X + (rect.Width / 4);
    
                //CheckBox checkboxHeader = new CheckBox();
                //checkboxHeader.Name = "checkboxHeader";
                //checkboxHeader.Size = new Size(18, 18);
                //checkboxHeader.Location = rect.Location;
                //checkboxHeader.CheckedChanged += new EventHandler(checkboxHeader_CheckedChanged);
    
    
    
              //  dataGridView1.Controls.Add(checkboxHeader);
                //this.dataGridView1.bin
            }
            void ckBox_CheckedChanged(object sender, EventArgs e)
            {
    
                for (int j = 0; j < this.dataGridView1.RowCount; j++)
                {
    
                    this.dataGridView1[0, j].Value = this.ckBox.Checked;
    
                }
    
                this.dataGridView1.EndEdit();
    
            }
    see out put snashot too ..


    can any one tell me how to put header text box shown in image in the column where written selected.please necessary ammendmnet in code
    Attached Images Attached Images  
    There is no achievement without goals

  2. #2
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,024

    Re: header checkbox in datagrid view

    Do you want to replace Selected Header with a checkbox control that function as checkall?

    Greg
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width