Jump to content

Duplicidade no Grid


Ralado

Recommended Posts

boa noite galera estou tentando verificar se ja existe um registro no grid, mas não estou conseguindo

meu código é o seguinte 

criei o método segue abaixo

 //pesquisa se tem registro duplicado no grid
        public static bool Duplicidade(this DataGridView pValor, string pColumn, string pValorComp)
        {
            bool retorno = false;
            foreach (DataGridViewRow item in pValor.Rows)
            {
                if (item.Cells[pColumn].Value.ToString() == pValorComp) retorno = true;
            }
            return retorno;
        }

e aqui o código do botão onde ele vai verificar

// Adiciona os Produtos ao Grid

private void btnAdicionar_Click(object sender, EventArgs e)
        {
            if (gProduto == null)
            {
                MessageBox.Show("Nenhum produto foi selecionado.");
            }
            else if (txtQuantidade.Text == string.Empty)
            {
                MessageBox.Show("Quantidade está vazia.");
            }
            else if (gProduto.Estoque.Quantidade < txtQuantidade.Text.ToInt())
            {
                MessageBox.Show(string.Format("Produto com estoque abaixo do adicionado.\nEstoque Atual: {0}", gProduto.Estoque.Quantidade.ToString()));
            }

            else if (dgvItens.Duplicidade("clmCodProd", gProduto.IdProduto.ToString()) == true && btnAdicionar.Text == "Inserir")
                MessageBox.Show("O produto já foi selecionado.");
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.