Jump to content

Preencher TextBox C#


Alex Silveira Amaral

Recommended Posts

Em um Form1 tem um botão para pesquisar que abre um outro Form2 com um campo de pesquisa. Após preencher ou não esse campo, o resultado aparece numa DataGridView. Então escolhe a linha e os dados supostamente iriam preencher os TextBox do Form1. Porém quando passo o DataGridView como parâmetro de um método, os TextBox não se alteram. Irei deixar aqui o código do método que supostamente teria de preencher os TextBox:

public void EditFuncionario(DataGridView dataGridPesqFunc)
{
        DataGridViewRow row = dataGridPesqFunc.Rows[0];
        txtCod.Text = row.Cells["ID"].Value.ToString().Trim();
        txtNome.Text = row.Cells["Nome"].Value.ToString().Trim();
        txtCpf.Text = row.Cells["CPF"].Value.ToString().Trim();
        txtEmail.Text = row.Cells["Email"].Value.ToString().Trim();
        txtFixo.Text = row.Cells["Fixo"].Value.ToString().Trim();
        txtCel.Text = row.Cells["Celular"].Value.ToString().Trim();
        txtRua.Text = row.Cells["Rua"].Value.ToString().Trim();
        txtNumero.Text = row.Cells["Numero"].Value.ToString().Trim();
        txtBairro.Text = row.Cells["Bairro"].Value.ToString().Trim();
        txtComplemento.Text = row.Cells["Complemento"].Value.ToString().Trim();
        txtCidade.Text = row.Cells["Cidade"].Value.ToString().Trim();
        txtCep.Text = row.Cells["CEP"].Value.ToString().Trim();
        comboBoxEstados.SelectedItem = row.Cells["UF"].Value.ToString().Trim();
        btnAlterar.Enabled = true;
}

Aqui o mesmo código, porém eu coloquei um Console.WriteLine para comprovar que o parâmetro não está sem valores ou nulo.

public void EditFuncionario(DataGridView dataGridPesqFunc)
{
        DataGridViewRow row = dataGridPesqFunc.Rows[0];
        txtCod.Text = row.Cells["ID"].Value.ToString().Trim();
        Console.WriteLine("NOME = " + row.Cells["Nome"].Value.ToString().Trim());
        txtNome.Text = row.Cells["Nome"].Value.ToString().Trim();
        txtCpf.Text = row.Cells["CPF"].Value.ToString().Trim();
        txtEmail.Text = row.Cells["Email"].Value.ToString().Trim();
        txtFixo.Text = row.Cells["Fixo"].Value.ToString().Trim();
        txtCel.Text = row.Cells["Celular"].Value.ToString().Trim();
        txtRua.Text = row.Cells["Rua"].Value.ToString().Trim();
        txtNumero.Text = row.Cells["Numero"].Value.ToString().Trim();
        txtBairro.Text = row.Cells["Bairro"].Value.ToString().Trim();
        txtComplemento.Text = row.Cells["Complemento"].Value.ToString().Trim();
        txtCidade.Text = row.Cells["Cidade"].Value.ToString().Trim();
        txtCep.Text = row.Cells["CEP"].Value.ToString().Trim();
        comboBoxEstados.SelectedItem = row.Cells["UF"].Value.ToString().Trim();
        btnAlterar.Enabled = true;
}

A saída desse Console.WriteLine está mostrando corretamente, somente os TextBox que não alteram seu conteúdo.

Link to comment
Share on other sites

Faz debug e verifica, após a atribuição de um valor a uma caixa de texto, qual o valor que a mesma tem.
Pode dar-se o caso de estares a limpar as caixas de texto num outro evento se te aperceberes.

10 REM Generation 48K!
20 INPUT "URL:", A$
30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50
40 PRINT "404 Not Found"
50 PRINT "./M6 @ Portugal a Programar."

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.