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 = "";
}
}