DataGridView Selected Row Cell Data To TextBox or Label
Selected DataGridView Row Cell Data Display To Textbox Or Label Using Window Application C#.Net.
DEMO
C# CODING
Selected DataGridView Row Cell Data Display To Textbox Or Label Using Window Application C#.Net.
DEMO
C# CODING
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication2
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection
(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Drizzles\Documents\Visual Studio 2012\WindowsFormsApplication2\WindowsFormsApplication2\Database1.mdf;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("select * from country", con);
SqlDataAdapter adp=new SqlDataAdapter (cmd);
DataTable dt=new DataTable ();
adp.Fill(dt);
dataGridView1 . DataSource=dt;
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
lblCountry.Text = row.Cells[0].Value.ToString();
lblCity.Text = row.Cells[1].Value.ToString();
}
}
}
0 comments:
Post a Comment