Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Pravin GhadgeRank #1,340 · 1.3K reputationPosted Jul 6, 2012, 4:46 AM EDT
Satyapriya NayakRank #47 · 31.5K reputationPosted Jul 6, 2012, 4:50 AM EDT
Try this...
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()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
bindgrid();
}
private void bindgrid()
{
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
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;
con.Close();
}
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;
}
}
}
}
Refer
http://www.c-sharpcorner.com/Blogs/9555/click-any-cell-of-a-datagridview-its-corresponding-data-will.aspx
http://www.c-sharpcorner.com/Blogs/9554/select-any-row-of-a-datagridview-all-records-related-will-be.aspx
Thanks
backiyalakshmi K38 reputationPosted Jul 6, 2012, 10:23 PM EDT
i got the it thank u...
backiyalakshmi K38 reputationPosted Jul 10, 2012, 3:05 AM EDT
am having two forms in my project in form2 created datagridview its havng the memcode and memname in form1 having two textbox wen am click on the textbox1 it shud go and fetch the f memcode in form2 at the same time shud display the memname also in textbox2 in form1... please help me how can i do....????
backiyalakshmi K38 reputationPosted Jul 12, 2012, 12:15 AM EDT