点击datagridview任何单元格赋值别一个窗体Textbox中



 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 点击datagridview任何单元格赋值别一个窗体Textbox中
{
    public partial class Form1 : Form
    {

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 点击datagridview任何单元格赋值别一个窗体Textbox中
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
         
        }
        SqlConnection conn;
        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                conn = new SqlConnection("server=WINDOWS-CBBU2E6;database=OrderManagementSystem;Uid = liweilu; Pwd = liweilu123");
                SqlCommand cmd = new SqlCommand("select*from dbo.Table_2", conn);
                SqlDataAdapter sda = new SqlDataAdapter();
                sda.SelectCommand = cmd;
                DataSet ds = new DataSet();
                sda.Fill(ds, "dbo.Table_2");
                dataGridView1.DataSource = ds.Tables["dbo.Table_2"];


            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "软件提示");
                throw ex;
            }
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            string data1 = dataGridView1.SelectedCells[0].Value.ToString();
            string data2 = dataGridView1.SelectedCells[1].Value.ToString();
           string data3 = dataGridView1.SelectedCells[2].Value.ToString();
           string data4 = dataGridView1.SelectedCells[3].Value.ToString();
            Form2 frm = new Form2();
            frm.textBox1.Text = data1;
           frm.textBox2.Text = data2;
            frm.textBox3.Text = data3;
           frm.textBox4.Text = data4;
          // frm.tabControl1.Text = "tabPage2";
            frm.Show();
        }
    }
}
        publicusing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 点击datagridview任何单元格赋值别一个窗体Textbox中
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
         
        }
        SqlConnection conn;
        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                conn = new SqlConnection("server=WINDOWS-CBBU2E6;database=OrderManagementSystem;Uid = liweilu; Pwd = liweilu123");
                SqlCommand cmd = new SqlCommand("select*from dbo.Table_2", conn);
                SqlDataAdapter sda = new SqlDataAdapter();
                sda.SelectCommand = cmd;
                DataSet ds = new DataSet();
                sda.Fill(ds, "dbo.Table_2");
                dataGridView1.DataSource = ds.Tables["dbo.Table_2"];


            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "软件提示");
                throw ex;
            }
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            string data1 = dataGridView1.SelectedCells[0].Value.ToString();
            string data2 = dataGridView1.SelectedCells[1].Value.ToString();
           string data3 = dataGridView1.SelectedCells[2].Value.ToString();
           string data4 = dataGridView1.SelectedCells[3].Value.ToString();
            Form2 frm = new Form2();
            frm.textBox1.Text = data1;
           frm.textBox2.Text = data2;
            frm.textBox3.Text = data3;
           frm.textBox4.Text = data4;
          // frm.tabControl1.Text = "tabPage2";
            frm.Show();
        }
    }
}
        {
            InitializeComponent();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
         
        }
        SqlConnection conn;
        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                conn = new SqlConnection("server=WINDOWS-CBBU2E6;database=OrderManagementSystem;Uid = liweilu; Pwd = liweilu123");
                SqlCommand cmd = new SqlCommand("select*from dbo.Table_2", conn);
                SqlDataAdapter sda = new SqlDataAdapter();
                sda.SelectCommand = cmd;
                DataSet ds = new DataSet();
                sda.Fill(ds, "dbo.Table_2");
                dataGridView1.DataSource = ds.Tables["dbo.Table_2"];


            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "软件提示");
                throw ex;
            }
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            string data1 = dataGridView1.SelectedCells[0].Value.ToString();
            string data2 = dataGridView1.SelectedCells[1].Value.ToString();
           string data3 = dataGridView1.SelectedCells[2].Value.ToString();
           string data4 = dataGridView1.SelectedCells[3].Value.ToString();
            Form2 frm = new Form2();
            frm.textBox1.Text = data1;
           frm.textBox2.Text = data2;
            frm.textBox3.Text = data3;
           frm.textBox4.Text = data4;
          // frm.tabControl1.Text = "tabPage2";
            frm.Show();
        }
    }
}

你可能感兴趣的:(点击datagridview任何单元格赋值别一个窗体Textbox中)