Wednesday 30 April 2014

Display selected Row from datagrid view to textBoxes in window application


                                                                                                                                               Previous..
                                                                                                                                                  Next..

Here i will explain how display selected row from datagrid view to textboxes.

Step(1):- Form..
Drag and down a datagrid view and textboxes.For this you see tutorial6 and tutorial14. From these tutorial you will learn how insert data in database and how to show database data in datagridview.

Step(2):- Code..
Click on DataGrid View and write this code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace First_Csharp_app
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

        }

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
    SqlConnection con = new SqlConnection("server = MUNESH\\SQL2008R2;Database=data;UID=sa;Password=123;");
   
  if(e.RowIndex >=0)
{
  
   DataGridViewRow row = this.datagridview1.Rows[e.RowIndex];
    if (cell != null)
    
        id_txt.Text = row.Cells["ID"].Value.ToString();
       textBox1.Text = row.Cells["FirsName"].Value.ToString();
       textBox1.Text = row.Cells["LastName"].Value.ToString();
        textBox3.Text = row.Cells["Age"].Value.ToString();
    }
}

Step(3):- Output..
Run your application.
                                                                                                                                               Previous..
                                                                                                                                                  Next..

1 comment:

C# program Selection Sorting

Selection sort is a straightforward sorting algorithm. This algorithm search for the smallest number in the elements array and then swap i...