How to manipulate data inside pages using tabcontrol

0

Good morning. I have a tabcontrol with two pages, I think we can say so, on page 1 I have a datagridview that in column [0] brings numbers of notes, and on page 2 I have a txtbox that I want to be filled with the value that I select on the page 1 in the datagridview, now how can I get the data from the column in the datagridview that is on page 1 and take the value selected for the textbox on page 2. Thank you very much in advance.  Here's my TabControl code

public partial class frmComissaoPic : Form
    {
        SqlConnection conex = new SqlConnection(Properties.Settings.Default.DADOSTSTConnectionString);
        public frmComissaoPic()
        {
             InitializeComponent();
        }
        public SqlConnection conexaoDADOSTST(bool fecharAntes)
        {
            if (fecharAntes)
            {
                conex.Close();
            }

            if (conex.State == ConnectionState.Closed)
            {
                conex.Open();
            }

            return conex;
        }
        private void frmComissaoPic_Load(object sender, EventArgs e)
        {

        }
        private void ListaGridAltera()
        {
            try
            {
                SqlCommand altera = new SqlCommand("usp_SelecaoAjusteComissao", conexaoDADOSTST(true));
                altera.Parameters.AddWithValue("@NOTA", this.txt_nota.Text);
                altera.CommandType = CommandType.StoredProcedure;
                altera.ExecuteNonQuery();

                SqlDataAdapter dados = new SqlDataAdapter(altera);
                DataTable dtLista = new DataTable();
                dados.Fill(dtLista);

                dgw_alteracomissao.DataSource = dtLista;

            }
            catch
            {
                MessageBox.Show("Não exstem dados digitados para a consulta, por favor verificar!!!");
                return;
            }
        }
        private void bln_gerar_Click(object sender, EventArgs e)
        {
            try
            {
                SqlCommand geracomissao = new SqlCommand("usp_RelatorioComissao", conexaoDADOSTST(true));
                geracomissao.Parameters.AddWithValue("@VENDEDOR", this.txt_vendedor.Text);
                geracomissao.Parameters.AddWithValue("@DTINICIAL", this.txt_dtinicial.Text);
                geracomissao.Parameters.AddWithValue("@DTFINAL", this.txt_dtfinal.Text);
                geracomissao.CommandType = CommandType.StoredProcedure;
                geracomissao.ExecuteNonQuery();

                SqlDataAdapter dados = new SqlDataAdapter(geracomissao);
                DataTable dtLista = new DataTable();
                dados.Fill(dtLista);

                dgw_comissao.DataSource = dtLista;

                dgw_comissao.Columns["NOTA"].ReadOnly = true;
                dgw_comissao.Columns["CLIENTE"].ReadOnly = true;
                dgw_comissao.Columns["PRODUTO"].ReadOnly = true;
                dgw_comissao.Columns["VALOR PARCELA"].ReadOnly = true;
                dgw_comissao.Columns["PARCELA S/ IMPOSTO"].ReadOnly = true;
                dgw_comissao.Columns["VENCIMENTO"].ReadOnly = true;
                dgw_comissao.Columns["PREÇO VENDA"].ReadOnly = true;
                dgw_comissao.Columns["COMISSÃO VENDEDOR"].Visible = false;

            }
            catch
            {
                MessageBox.Show("Não exstem dados digitados para a consulta, por favor verificar!!!");
                return;
            }
        }
        private void btn_pesquisar_Click(object sender, EventArgs e)
        {
            ListaGridAltera();
        }
        private void dgw_alteracomissao_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewRow row = this.dgw_alteracomissao.Rows[e.RowIndex];

            txt_nfe.Text         = row.Cells[0].Value.ToString();
            txt_pedido.Text      = row.Cells[1].Value.ToString();
            txt_item.Text        = row.Cells[2].Value.ToString();
                }

        private void btn_gravar_Click(object sender, EventArgs e)
        {
            SqlCommand update = new SqlCommand("usp_AlteraComissao", conexaoDADOSTST(true));
            update.Parameters.AddWithValue("@NOTA", this.txt_nfe.Text);
            update.Parameters.AddWithValue("@PEDIDO", this.txt_pedido.Text);
            update.Parameters.AddWithValue("@ITEM", this.txt_item.Text);
            update.Parameters.AddWithValue("@DESEJAVEL", float.Parse(this.txt_desejavel.Text));
            update.CommandType = CommandType.StoredProcedure;
            update.ExecuteNonQuery();
            ListaGridAltera();

            txt_nfe.Text         = "";
            txt_pedido.Text      = "";
            txt_item.Text        = "";
            txt_desejavel.Text   = "";
        }
    }
    
asked by anonymous 26.10.2017 / 19:55

1 answer

0

So, based on the information you passed, suppose we have tab1 with the following items:

gridview - GridTest; 2 columns - column0, column1; push button;

on tab2: 2 textbox - id, name;

and the send button code:

    private void enviar_Click(object sender, EventArgs e)
    {
        id.Text = GridTeste.CurrentRow.Cells[0].Value.ToString();
        nome.Text = GridTeste.CurrentRow.Cells[1].Value.ToString();
    }

obs: the value between [] is referring to the column, the count starts at 0, so if you have 2 columns, they would be 0 and 1, if you have 3 they would be 0, 1 and 2, and so on, I hope I have helped.

The content of the submit button method can be used in a different event handler, dearly want to send the values without having to use the button.

    
26.10.2017 / 21:34