This is a migrated thread and some comments may be shown as answers.

How Set e.value in CellValidating event

3 Answers 91 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Fernando Siguenza
Top achievements
Rank 1
Fernando Siguenza asked on 24 Jan 2012, 12:31 AM
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





3 Answers, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 26 Jan 2012, 04:43 PM
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).

0
Fernando Siguenza
Top achievements
Rank 1
answered on 27 Jan 2012, 06:44 PM
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
0
Julian Benkov
Telerik team
answered on 01 Feb 2012, 04:22 PM
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).

Tags
GridView
Asked by
Fernando Siguenza
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Fernando Siguenza
Top achievements
Rank 1
Share this question
or