I am having a grid view when i double click on the row its value should display in the text box and combobox respectively but m getting error and its not displaying ...
Pls help me ...
Here s my code
Pls help me ...
Here s my code
private void dataGridView1_DoubleClick(object sender, EventArgs e)
{
{
try
{
DataTable dt = new DataTable();
OleDbDataAdapter da = new OleDbDataAdapter("select class_standard,subjectcode,subjectname from tblsubject where subjectcode=" +
Convert.ToInt16(dataGridView1.SelectedRows[0].Cells[0].Value.ToString()) + " ", con);
da.Fill(dt);
//display now the record in the textbox
textboxsubcode.Text = dt.Rows[0][0].ToString();
textboxsubname.Text = dt.Rows[0][1].ToString();
cmboboxclass.Text = dt.Rows[0][2].ToString();
}
catch (Exception error)
{
MessageBox.Show(error.ToString());
}
}
Satyapriya NayakPosted Jul 17, 2012, 2:42 PM
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_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
txt_sno.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();
txt_name.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
txt_address.Text = dataGridView1.CurrentRow.Cells[2].Value.ToString();
comboBox1.Text= dataGridView1.CurrentRow.Cells[3].Value.ToString();
}
}
}
Thanks
If this post helps you mark it as answer
rashmi kcPosted Jul 17, 2012, 3:42 PM
rashmi kcPosted Jul 17, 2012, 3:14 PM