Home Forums WPF controls Xceed DataGrid for WPF Fill related cells on InsertionRow

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #26910 |

    Hello !!

     I need to fill by code the content of another cell when the content of the current cell changes.

     
    I’m trying to do it in the Validate Method of the cell’s column validation’s rule. The code i’ve used is as follows:

     

    —————————————————————————————————
             public override ValidationResult Validate(object value, CultureInfo culture, CellValidationContext context)
            {
                switch (context.Cell.ParentColumn.FieldName)
                {
                    case “IdConcepto”:
                        Concepto conc = ComunidadBM_WPF.App.AccesoDB.ObtenerConcepto(Convert.ToInt32(value));
                        if ( conc == null)
                            return new ValidationResult(false, string.Format(“No existe el concepto con ID: {0}”, value));
                        else
                        {
                            System.Data.DataRow filaOrigen = (System.Data.DataRow)context.DataItem;
                            filaOrigen.BeginEdit();
                            filaOrigen[“Descripcion”] = conc.Descripcion;
                            filaOrigen[“Precio”] = conc.Importe;
                            if (filaOrigen.IsNull(“Unidades”)) filaOrigen[“Unidades”] = 1M;
                            filaOrigen[“ImporteTotal”] = Convert.ToDecimal(conc.Importe * Convert.ToDecimal(filaOrigen[“Unidades”]));
                            filaOrigen.EndEdit();
                        }
                        break;

                } 

               return new ValidationResult(true,null);

        }

    ———————————————————————————

     

    This works fine for rows other that the insertion row, so…

     

    ¿how can i update related cells on insertion row when the content of another cell changes ?

     
    thanks in advance !!
     

    Imported from legacy forums. Posted by Miguel (had 2052 views)

    User (Old forums)
    Member
    Post count: 23064

    Hello !!

     When the user pess the Enter key in the insertion row, the values entered programatically via the Validate method are stored in a new datarow correctly and shown as a new item in the grid rows.

    But I want to show those values in the insertior row when a cell changes. Here’s a more detailed description of my goal:

     

    I have a cell that stores id’s and when an id is entered, other cells must update their content accordingly to the cell that has the id.

     
    The code shown above works well for normal items, but not for the insertion row.

     
    So… ¿ how can i get this behavior on the insertion row ? ¿ How can i shown the values of the cells modified by code in the insertion row?

     

    Thanks !!
     

    Imported from legacy forums. Posted by Miguel (had 639 views)

    Xceed Support
    Member
    Post count: 5658

    Unfortunately, this is currently not possible.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 474 views)

    User (Old forums)
    Member
    Post count: 23064

    Hopefully someone else will find this useful — I know this thread was opened a year ago but I didn’t find the answer I needed and I wanted similar behavior.

    I’m using v3.1.9175.12000 of the WPF DataGrid.

    Here’s my solution:

                    <xcdg:Column FieldName=”[SponsorNumber]” Title=”Sponsor Number” Width=”100″
                        CellEditor=”{StaticResource numericTextEditor}”>
                        <xcdg:Column.CellValidationRules>
                            <cli:RegExCellValidation/>
                            <cli:SponsorNumberCellValidation/>
                        </xcdg:Column.CellValidationRules>
                    </xcdg:Column>
                    <xcdg:Column FieldName=”[SponsorName]” Title=”Sponsor Name” Width=”200″ ReadOnly=”true”/>

    I have two validation rules, one that verifies the particular format of the entry and then the actual validation of the number.

    The SponsorNumberCellValidation performs a lookup against a data source for the sponsor, returning the name if found.

         public class SponsorNumberCellValidation : CellValidationRule
        {
            public
            override
            ValidationResult
            Validate(
                object value,
                System.Globalization.CultureInfo cultureInfo,
                CellValidationContext context
                )
            {
                //
                // The Sponsor Number must be provided.
                //
                if (null == value)
                {
                    return new ValidationResult( false, String.Format( “{0} cannot be empty.”, context.Cell.ParentColumn.Title ) );
                }

                String sponsorName = SponsorsDataSource.LookupSponsorName( (int) value );
               
                //
                // Update the Sponsor, if the lookup fails, we still want to clear the current entry.
                //
                context.Cell.ParentRow.Cells[ “[SponsorName]” ].Content = sponsorName;

                //
                // Validation fails if the sponsor number does not exist.
                //
                if (sponsorName == null)
                {
                    return new ValidationResult( false, “Sponsor Number is invalid.” );
                }
               
                return ValidationResult.ValidResult;
            }
        }

     

     

    Imported from legacy forums. Posted by Bryan (had 2242 views)

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.