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 = "";
}
}
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.
– Junior Guerreiro
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();
– Brewerton Santos
if I can’t, I’ll do an example project and put another response with the code.
– Brewerton Santos
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
– Junior Guerreiro
I’ll rephrase my answer.
– Brewerton Santos
Thank you very much..
– Junior Guerreiro
check if you are now answering your reply request.
– Brewerton Santos
Thank you very much Thiago was just what I needed...
– Junior Guerreiro