Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
5 views1 page

Grid Click Display

The document is a C# code snippet for a Windows Forms application that connects to a SQL database. It includes a form that loads data from a specified table into a DataGridView and displays selected row details, including an image, in corresponding text fields and a picture box. The code handles the loading of data and the display of selected row information when a cell is clicked.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Grid Click Display

The document is a C# code snippet for a Windows Forms application that connects to a SQL database. It includes a form that loads data from a specified table into a DataGridView and displays selected row details, including an image, in corresponding text fields and a picture box. The code handles the loading of data and the display of selected row information when a cell is clicked.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

using System;

using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

namespace YourNamespace
{
public partial class YourForm : Form
{
SqlConnection con = new SqlConnection("your_connection_string");

public YourForm()
{
InitializeComponent();
}

private void YourForm_Load(object sender, EventArgs e)


{
LoadGridData();
}

private void LoadGridData()


{
SqlDataAdapter da = new SqlDataAdapter("SELECT id, name, status, image
FROM your_table", con);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
}

private void dataGridView1_CellClick(object sender,


DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
DataGridViewRow row = dataGridView1.Rows[e.RowIndex];

txtName.Text = row.Cells["name"].Value.ToString();
lblStatus.Text = row.Cells["status"].Value.ToString();

if (row.Cells["image"].Value != DBNull.Value)
{
byte[] imageData = (byte[])row.Cells["image"].Value;
using (MemoryStream ms = new MemoryStream(imageData))
{
pictureBox1.Image = Image.FromStream(ms);
}
}
else
{
pictureBox1.Image = null;
}
}
}
}
}

You might also like