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
ReplyDeletegood
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
ReplyDeleteFather's day 2018
ReplyDeleteFather's day
Fathers day Gifts
Fathers day T shirts
Fathers day T shirt
Fathers day 2018 gifts idea
Fathers day 2018 gifts
Fathers day 2018 T shirts
Fathers day 2018 gift
Fathers day gifts idea
Fathers day 2018 T shirt
Fathers day 2018 Gifts idea
Any 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
ReplyDeletePositive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work. https://zetamatic.com/downloads/wp-paint-pro/
ReplyDelete