Advertisement
In This Article I will Explain How to add Edit and Delete Button Links in DataGridView.
In my Pervious Article I Explained How to display Data in Datagridview and How to Set Auto Generate SNO in DataGridView.
Now i want to add link buttons to datagridview by using 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; using System.Data.SqlClient; namespace DatagridviewExample { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { displayDataGridView(); DataGridViewLinkColumn Editlink = new DataGridViewLinkColumn(); Editlink.UseColumnTextForLinkValue = true; Editlink.HeaderText = "Edit"; Editlink.DataPropertyName = "lnkColumn"; Editlink.LinkBehavior = LinkBehavior.SystemDefault; Editlink.Text = "Edit"; dataGridView1.Columns.Add(Editlink); DataGridViewLinkColumn Deletelink = new DataGridViewLinkColumn(); Deletelink.UseColumnTextForLinkValue = true; Deletelink.HeaderText = "delete"; Deletelink.DataPropertyName = "lnkColumn"; Deletelink.LinkBehavior = LinkBehavior.SystemDefault; Deletelink.Text = "Delete"; dataGridView1.Columns.Add(Deletelink); } public void displayDataGridView() { SqlConnection con = new SqlConnection("Data Source = CHINNU;Initial Catalog = dotnetdb;Uid = sa;Password = password123;"); { SqlCommand cmd; cmd = new SqlCommand("select * from Employee", con); cmd.CommandType = CommandType.Text; SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); dataGridView1.DataSource = ds.Tables[0]; dataGridView1.AutoGenerateColumns = false; dataGridView1.AllowUserToAddRows = false; int i = 1; foreach (DataGridViewRow row in dataGridView1.Rows) { row.Cells["SNO"].Value = i; i++; } } } } }OutPut:
Very useful ....Thanks
ReplyDeleteuseful.
ReplyDeletegood
ReplyDeletehow to handle the edit button event
ReplyDeleteyes how can we make that links work?
DeleteHow these link work????
ReplyDeletejust go to the datagridview column where you add this link and double click there after that the key press event is generated..................simple..........
DeleteHoooow where is the datagridview column which one should I press
Deletejust go to the datagridview column where you add this link and double click there after that the key press event is generated..................simple..........
ReplyDeletePELOTUDOW
Deletehow to handle those two buttons
ReplyDeleteI am very enjoyed for this blog. Its an informative topic. It help me very much to solve some problems. Its opportunity are so fantastic and working style so speedy. ucmini
ReplyDeleteAny sort of information that is incorporated into the spared shape can be revised and furthermore can be transported in and sent out in XML design from/to the DMS with any database. edit pdf
ReplyDeleteI would like to say that this blog really convinced me to do it! Thanks, very good post. 2020 rap songs
ReplyDeleteVERY AMAZING CONTETENT .ELLA JAMEX
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteEnormous images should be resized and reshaped. Like for site, PNG and JPG will be awesome.
ReplyDeleteeCommerce Product Photo Editing Service
It assist you with survey pictures in your collections and make a slideshow, add photos together to make new one, and resize to your number one and make enlivened gif effectively by adding photos or images.
ReplyDeleteProduct Photo Editing
Your blog is a hidden gem.
ReplyDeleteVisit Here: Amazon photo editing service