Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to make a click event on the columns header of datagridview. i.e.,when i click the header whole column will disable ...pls help me on this.

here is my code

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace tushar29
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            initialize_datagridview(5, 5);
        }

        void initialize_datagridview(int rows,
                                      int columns)
        {

            dataGridView1.EditMode = DataGridViewEditMode.EditOnEnter;

            for (int i = 0; (i < columns); i++)
            {
                string i_plus_one = (i + 1).ToString();

                dataGridView1.Columns.Add("Col" + i_plus_one,
                                            "Stage" + i_plus_one);
            }


            dataGridView1.Rows.Add(rows);



            dataGridView1.EditingControlShowing +=
                new DataGridViewEditingControlShowingEventHandler(
                    dataGridView1_EditingControlShowing);
        }

        void dataGridView1_EditingControlShowing(
                   object sender,
                   DataGridViewEditingControlShowingEventArgs e)
        { }
    }
}
Posted
Comments
gggustafson 29-May-14 15:52pm    
You are asking the same question only for a header. As I responded to the other question, go to http://www.4guysfromrolla.com/ and search for DataGridView.
TusharZoo 29-May-14 23:15pm    
ok ...i think there is the difference between header event and button event on datagridview..
but i want to know both..thank you for giving me the link ..i am searching but if you have any solution pls give me..

1 solution

Use DataGridView.ColumnHeaderMouseClick event
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900