How to manipulate data inside pages using tabcontrol

Asked

Viewed 91 times

0

Good Tare. 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 I select on page 1 in datagridview, now how can I take the data from the column on the datagridview that is on page 1 and take the selected value to the textbox on page 2. Thank you in advance. Follow 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   = "";
        }
    }

1 answer

0


So, based on the information you’ve passed on, suppose we have the aba1 with the following items:

gridview - Gridteste; 2 columns - column, column 1; button - send;

in aba2: 2 textbox - id, name;

and 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 [] refers to 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’ve helped.

the contents of the send button method can be used in a different, expensive event handler want to send the values without having to use the button.

  • Thiago Valew by the attention, then and the next in the tab1 I have a datagrid where I need to get the value of the column 0 I select and this value go to a textbox that is in the tab2 will be that I could explain better.

  • to get the value use an event handler to capture the field value and then play in the textbox: tab2textbox.Text = Gridviewname.Rows[Gridviewname.Selectedindex]. Cells[1].Text.Tostring();

  • if I can’t, I’ll do an example project and put another response with the code.

  • Thiago and that’s just that I’m putting this command inside the datagrid cellclik and this giving error in the selectindex is not finding

  • I’ll rephrase my answer.

  • Thank you very much..

  • check if you are now answering your reply request.

  • Thank you very much Thiago was just what I needed...

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.