ریختن مقادیر سلول های DataGridView در TextBox
کد:
using System;
using System.Windows.Forms;
namespace DGAndTextBox
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.dataGridView1.Columns.Add("Column1", "Column1");
this.dataGridView1.Columns.Add("Column2", "Column2");
this.dataGridView1.Columns.Add("Column3", "Column3");
this.dataGridView1.Rows.Add(new object[] { "Ottima", "Ottima1", "20" });
this.dataGridView1.Rows.Add(new object[] { "ali_Eagle", "Ottima2", "30" });
this.dataGridView1.Rows.Add(new object[] { "iman_taktaz", "Ottima3", "31" });
this.dataGridView1.Rows.Add(new object[] { "spoof", "Ottima4", "30" });
}
private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex < 0 || e.ColumnIndex < 0)
return;
textBox1.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
textBox2.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
textBox3.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
}
}
}