How Set e.value in CellValidating event

4 posts, 0 answers
  1. Fernando Siguenza
    Fernando Siguenza avatar
    3 posts
    Member since:
    Mar 2010

    Posted 23 Jan 2012 Link to this post

    Hello, i'm  trying to validate a cell in the CellValidating event,but i have this problem.

    When i enter the any value in the cell, i search in database por entered by the user.
    For example the user entered x3
    i have this code

    case "Codigo":
                       if (grdContrato.IsInEditMode && e.Value != null)
                       {
                           ArticuloEntity articulo = new ArticuloEntity();
                           articulo = ArticuloNeg.ObtenerArticuloById(e.Value.ToString());
                           if (!string.IsNullOrEmpty(articulo.ArticuloId))
                           {
                               this.grdContrato.CurrentCell.Value=articulo.ArticuloId;
                               contrato.Detalle[e.RowIndex].ArticuloId = articulo.ArticuloId;
                               contrato.Detalle[e.RowIndex].Descripcion = articulo.Descripcion;
                           }
                           else
                           {
                               BuscarArticulosForm buscarForm = new BuscarArticulosForm(e.Value.ToString(), "Codigo");
                               buscarForm.ShowDialog();
                               if (!string.IsNullOrEmpty(buscarForm.CodigoSeleccionado))
                               {
                                   this.grdContrato.CurrentCell.Value = buscarForm.CodigoSeleccionado;
                                   contrato.Detalle[e.RowIndex].ArticuloId = buscarForm.CodigoSeleccionado;
                                   contrato.Detalle[e.RowIndex].Descripcion = buscarForm.ArticuloSeleccionado;
                               }
                           }
                       }
                       break;

    And when the event ends, the e.value have x3, but the contrato.Detalle[e.RowIndex].ArticuloId  have the real code "x3450".
    the contrato.Detalle[index].ArticuloId,is the property of the BindingList<>, and this bound to the gridview.
    But when the event ends, the contrato.Detalle[e.RowIndex].ArticuloId have the x3 againg.

    Whow i can set to e.value , so that the event ends the cell have the value x3450 and not the user entered value
    i try with this.grdContrato.CurrentCell.Value = buscarForm.CodigoSeleccionado;  but do not work.

    Tanks





  2. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 26 Jan 2012 Link to this post

    Hello Fernando,

    I would kindly ask you to provide me with additional details about your scenario. It will be best if you can send us a sample project where we can reproduce the issue. This will allow us to understand the exact behavior and the circumstances in which it occurs. Hence, we will be able to assist you further.

    Thank you for your cooperation. I am looking forward to your response.
    Kind regards,
    Julian Benkov
    the Telerik team

    SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).

  3. Fernando Siguenza
    Fernando Siguenza avatar
    3 posts
    Member since:
    Mar 2010

    Posted 27 Jan 2012 Link to this post

    Hello, thanks for your help, i make a little sample.

    Sample

    In the sample, i have 2 forms, in the form 1 when i press a button, i run the form2 to the user select a product, but when the user select this product, the selected code is not binded with the grid.

    Tanks
  4. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 01 Feb 2012 Link to this post

    Hi Fernando,

    The RadGridView control in your scenario is bound to 'listDetalle' BindingList and if you want to the changes of the object to notify RadGridView to refresh its content, you should implement INotifyPropertyChanged interface at your custom object. More information you can find in our online documentation. Here is a simple example:

    public class ContratoDetalleEntity : INotifyPropertyChanged
    {
        private string articuloId;
        private int contador;
        private string ubicacion;
        private string serieId;
        private string description;
     
        public string ArticuloId
        {
            get { return this.articuloId; }
            set
            {
                if (this.articuloId != value)
                {
                    this.articuloId = value;
                    OnPropertyChanged("ArticuloId");
                }
            }
        }
     
        public string Descripcion
        {
            get { return this.description; }
            set
            {
                if (this.description != value)
                {
                    this.description = value;
                    OnPropertyChanged("Description");
                }
            }
        }
     
        public string SerieId
        {
            get { return this.serieId; }
            set
            {
                if (this.serieId != value)
                {
                    this.serieId = value;
                    OnPropertyChanged("SerieId");
                }
            }
        }
     
        public string Ubicacion
        {
            get { return this.ubicacion; }
            set
            {
                if (this.ubicacion != value)
                {
                    this.ubicacion = value;
                    OnPropertyChanged("Ubicacion");
                }
            }
        }
     
        public int Contador
        {
            get { return this.contador; }
            set
            {
                if (this.contador != value)
                {
                    this.contador = value;
                    OnPropertyChanged("Contador");
                }
            }
        }
     
        public event PropertyChangedEventHandler PropertyChanged;
        
     
        protected virtual void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }

    I hope this helps.

    Greetings,
    Julian Benkov
    the Telerik team

    SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).

Back to Top