Capture datagrid id

Asked

Viewed 183 times

1

If I want to capture the value of the column ID of the selected row, I need to necessarily use the wind SelectionChanged, what is to be triggered at each line exchange on the datagrid? Or just with the dataGridView1.CurrentRow.Cells[0].Value, I already get it?

That’s my method, if you want to understand the context:

private void EfetuarPedido()
        {
            int id_Posicao_Selecionada = 0;
            int quantidade_Posicao = 0;

            tratarErro.Clear();

            quantidade_Posicao = Convert.ToInt32(dgvPosicoesParaPedido.CurrentRow.Cells[3].Value);
            id_Posicao_Selecionada = Convert.ToInt32(dgvPosicoesParaPedido.CurrentRow.Cells[0].Value);

            if (Convert.ToDouble(txtPedidoCodigo.Text) < 999999999999)
            {
                tratarErro.SetError(txtPedidoCodigo, "Código inválido");
            }

            if (Convert.ToInt32(txtPedidoQuantidade.Text) <= 0)
            {
                tratarErro.SetError(txtPedidoQuantidade, "Quantidade não pode ser nula");
            }
            else if (quantidade_Posicao > (Convert.ToInt32(txtPedidoQuantidade.Text)))
            {
                tratarErro.SetError(txtPedidoQuantidade, "Não há unidades necessárias na posição escolhida");
            }
            else if(Convert.ToDouble(txtPedidoCodigo.Text) > 999999999999)
            {
                validar.Validacao_FazerPedido(Convert.ToDouble(txtPedidoCodigo.Text), Convert.ToInt32(txtPedidoQuantidade.Text), id_Posicao_Selecionada, txtReorganizarDescricao.Text); 
            }
        }

1 answer

1


The event would only be useful in your case if you need to update other fields whenever the user makes a change on the selected row, if it is not so just get the id straight from the table should already solve.

  • Oh thanks, in case, will not update any field, this method I will assign to the event click of a button, so there is no way it select another line after firing the click event, thanks for having clarified me this doubt. I was thinking that it only worked with the Event Good, like the pixel values of Axis X and Y of the Chart that only works in the Paint Event

Browser other questions tagged

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