How to get the particular datagridcell value to textbox??
How to get the particular datagridcell value to textbox??
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
backiyalakshmi KPosted Jul 12, 2012, 4:15 AM
backiyalakshmi KPosted Jul 10, 2012, 7:05 AM
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 KPosted Jul 7, 2012, 2:23 AM
i got the it thank u...
Satyapriya NayakPosted Jul 6, 2012, 8:50 AM
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
Pravin GhadgePosted Jul 6, 2012, 8:46 AM