Пример #1
0
        private void AtualizarGrid(Cliente Cliente, bool booExcluir)
        {
            try
            {
                object FiltroExcluir = null;

                if (booExcluir)
                {
                    FiltroExcluir         = (LocalizarFiltroExcluir(dgwColecao) as Cliente).GetChavePrimaria();
                    dgwColecao.DataSource = null;
                    clienteCollection.Remove(Cliente);
                }
                else
                {
                    if (Cliente != null)
                    {
                        var Item = from p in clienteCollection
                                   where p.GetChavePrimaria() == Cliente.GetChavePrimaria()
                                   select p;

                        if (Item.Count() == 1)
                        {
                            Cliente ClienteSelecionado = Item.First();
                            ClienteSelecionado = Cliente;
                        }
                        else
                        {
                            clienteCollection.Add(Cliente);
                        }
                    }
                    else
                    {
                        while (backgroundWorker1.IsBusy)
                        {
                            Application.DoEvents();
                        }
                        object[] args = new object[3];
                        args[0] = "VMPesquisarCliente";
                        args[1] = this.txtPesquisar.Text;
                        args[2] = cbxAtivos.SelectedValue;
                        backgroundWorker1.RunWorkerAsync(args);
                        while (backgroundWorker1.IsBusy)
                        {
                            Application.DoEvents();
                        }
                    }
                }

                dgwColecao.DataSource = null;
                if (clienteCollection.Count() > 0)
                {
                    dgwColecao.DataSource = clienteCollection.ToList <Cliente>();
                }

                txtRegistros.Text = dgwColecao.Rows.Count.ToString();

                //if (objCliente != null)
                //    LocalizarIndexLinha(dgwColecao, FiltroExcluir == null ? objCliente.GetChavePrimaria() : FiltroExcluir);

                dgwColecao.Update();
                dgwColecao.Refresh();

                if (dgwColecao.RowCount > 0)
                {
                    dgwColecao.Focus();
                }
            }
            catch (Exception ex)
            {
                Exceptionerro(ex);
            }
        }