
Background : Some time user need to do Something like want to Delete row by Clicking Button inside the DataGridView. Lets Start Fisrt of All Drag one DataGridView With Some Column inside it You can do it by "Smart Tag" at the Right Hand Side Corner at Form's Load Event Add Another ColumnThat Will have Button inside it to do So {codecitation class="brush: csharp; gutter: true;" width="650px"} private void Form1_Load(object sender, EventArgs e) { // Create New instance of the Column DataGridViewButtonColumn bcol = new DataGridViewButtonColumn();
// this will be the Header of the New Added Column bcol.HeaderText = "Button Column "; // Text Displayed on the Button bcol.Text = "Click Me"; bcol.Name = "btnClickMe"; // This Property will use Column Text as Button's Text Property bcol.UseColumnTextForButtonValue = true; //Finaly Add Column to the DataGridView dataGridView1.Columns.Add(bcol); } {/codecitation}
Now We have Added Column with Button in it in DataGridView Now We Want to Handle its Click Event Lets See how to do that {codecitation class="brush: csharp; gutter: true;" width="650px"} private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 1) {
//StateMents you Want to execute to Get Data } }
{/codecitation}
In Above Code we handle the Buttons Click event By CellContent Click So We have to Take Care Which Cell's Content Was Click
We Do so by DataGridViewCellEventArgs e
Now we have Button Column in 2nd Column of the DataGridView So
We have to Execute code if Cell is from Second column
so
{codecitation class="brush: csharp; gutter: true;" width="650px"}
if ( e.ColumnIndex == 1) {
// Code to Execute When Button is Clicked }
{/codecitation}
Thats it happy coding Thank You
| About the Author |
 |
| Kirtan Patel | - Bachelor of Computer Application . - File Handling with C# - Registry Programming With C#. - Knowledge of Virus Programming . - Working With third party controls like Telerik and Component Factory . - P/invoke Win32 API. - SQL Server Database Applications - Client/Server Database Programming Expertise in : C# , Asp.net ,Vb.net , SQL Server , Designing Elegant look Web interface Familiar With : C/C++ , Core Java , Java Script , Dream weaver templates , fire Works ,PHP ,Photo shop and Graphics Databases: Microsoft SQL Server 2005 , Microsoft Access and Some MySQL Occupation: Student |
|
|