.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal

Home >> Code Snippets >> Visual Studio >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Click any cell of a datagridview its corresponding data will be show in the textbox.

Posted By:satyapriyanayak       Posted Date: October 07, 2013    Points: 40    Category: Visual Studio    URL: http://www.dotnetspark.com  

We will know when we click any cell of a datagridview its corresponding data will be show in the textbox.

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.OleDb;
namespace Datagridview_select_textbox_data
    public partial class Form1 : Form
        string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
        OleDbCommand com;
        OleDbDataAdapter oledbda;
        string str;

        DataSet ds;
        public Form1()

        private void Form1_Load(object sender, EventArgs e)
        private void bindgrid()
            OleDbConnection con = new OleDbConnection(ConnectionString);
            str = "select * from employee";
            com = new OleDbCommand(str, con);
            oledbda = new OleDbDataAdapter(com);
            ds = new DataSet();
            oledbda.Fill(ds, "employee");
            dataGridView1.DataMember = "employee";
            dataGridView1.DataSource = ds;

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
            txt_sno.Text = "";
            bool FirstValue = true;
            foreach (DataGridViewCell cell in dataGridView1.SelectedCells)
                if (!FirstValue)
                    txt_sno.Text += ", ";
                txt_sno.Text += cell.Value.ToString();
                FirstValue = false;




Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend