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

cellendedit exception

0 Answers 17 Views
GridView
This is a migrated thread and some comments may be shown as answers.
mehmood ahmed
Top achievements
Rank 1
mehmood ahmed asked on 08 Dec 2011, 06:21 AM

HI..

I am receiving an exception but couldn't able to track the actual cause.

According to my Observation, i am adding a new object in datagrid and its losses the selectedItem of  datagrid.

Description is mentioned below:

 

 at Telerik.Windows.Controls.GridView.GridViewCell.RaiseCellEditEndedEvent(GridViewEditAction editAction)
   at Telerik.Windows.Controls.GridView.GridViewDataControl.PerformCellEditEnded(GridViewCell currentCell)
   at Telerik.Windows.Controls.GridView.GridViewDataControl.CommitCellEdit(GridViewCell currentCell, Boolean isLeavingRow)
   at Telerik.Windows.Controls.GridView.GridViewDataControl.CanCellBecomeCurrent(GridViewCell cell)
   at Telerik.Windows.Controls.GridView.GridViewCell.OnMouseLeftButtonDown(MouseButtonEventArgs e)
   at System.Windows.Controls.Control.OnMouseLeftButtonDown(Control ctrl, EventArgs e)
   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)

Source is mentioned at here:

 private void ValidateProposalRentalTerms()
       
{
           
if (dgStructRental != null && dgStructRental.Items != null)
           
{
               
if (dgStructRental.Items[firstRentalIndex] != null)
                    firstProposalRentalSlab
= ((proposalProxy.PROPOSALRENTALDETAILInfo)dgStructRental.Items[firstRentalIndex]);
               
if (firstProposalRentalSlab.STARTTRM != 1) firstProposalRentalSlab.STARTTRM = 1;

                selectedProposalRentalSlab
= ((proposalProxy.PROPOSALRENTALDETAILInfo)dgStructRental.SelectedItem);
               
if (selectedProposalRentalSlab == null) return;

               
if (selectedProposalRentalSlab.ENDTRM > ContractTerm)
               
{
                   
var validationMessages = new List<Controls.ValidationMessage>();
                    validationMessages
.Add(new Controls.ValidationMessage()
                   
{
                       
Type = Controls.MessageType.Warning,
                       
Description = "End term must be less than the contract terms."
                   
});
                   
this.validator.ShowWarningMessages(validationMessages);
                    selectedProposalRentalSlab
.ENDTRM = ContractTerm;
                   
return;
               
}
               
else if (selectedProposalRentalSlab.ENDTRM < ContractTerm)
               
{
                   
if (((proposalProxy.PROPOSALRENTALDETAILInfo)dgStructRental.Items[dgStructRental.Items.Count - 1]).ENDTRM != 0
                       
&& ((proposalProxy.PROPOSALRENTALDETAILInfo)dgStructRental.Items[dgStructRental.Items.Count - 1]).ENDTRM != ContractTerm)
                   
{
                       
var selectedItem = selectedProposalRentalSlab;
                        proposalProxy
.PROPOSALRENTALDETAILInfo proposalNewlyInsertedItem = AddProposalRentalSlab();
                        dgStructRental
.SelectedItem = selectedItem;
                        selectedProposalRentalSlab
= (PROPOSALRENTALDETAILInfo)dgStructRental.SelectedItem;                        
                   
}

                   
foreach (var item in dgStructRental.Items)
                   
{
                       
if (dgStructRental.Items.IndexOf(item) > 0)
                       
{
                           
var proposalRentalDetailItem = ((proposalProxy.PROPOSALRENTALDETAILInfo)item);
                           
var previousRentalDetailItem = ((proposalProxy.PROPOSALRENTALDETAILInfo)dgStructRental.Items[dgStructRental.Items.IndexOf(item) - 1]);

                           
if (proposalRentalDetailItem.STARTTRM <= previousRentalDetailItem.ENDTRM &&
                                previousRentalDetailItem
.ENDTRM == 0 && proposalRentalDetailItem.STARTTRM == 0)
                                proposalRentalDetailItem
.STARTTRM = proposalRentalDetailItem.STARTTRM + 1;
                           
else
                           
{
                               
if (previousRentalDetailItem.ENDTRM + 1 <= proposalRentalDetailItem.STARTTRM) { }

                               
else if (previousRentalDetailItem.STARTTRM > proposalRentalDetailItem.STARTTRM &&
                                         previousRentalDetailItem
.ENDTRM > proposalRentalDetailItem.ENDTRM
                                       
&& proposalRentalDetailItem.STARTTRM == 0 && proposalRentalDetailItem.ENDTRM == 0)
                               
{
                                    proposalRentalDetailItem
.STARTTRM = previousRentalDetailItem.ENDTRM + 1;
                                    proposalRentalDetailItem
.ENDTRM = ContractTerm;
                               
}
                               
else
                               
{
                                    proposalRentalDetailItem
.STARTTRM = previousRentalDetailItem.ENDTRM + 1;
                                    proposalRentalDetailItem
.ENDTRM = ContractTerm;
                               
}
                           
}

                           
if (previousRentalDetailItem.STARTTRM > previousRentalDetailItem.ENDTRM)
                           
{
                                previousRentalDetailItem
.ENDTRM = previousRentalDetailItem.STARTTRM + 1;
                                proposalRentalDetailItem
.STARTTRM = previousRentalDetailItem.ENDTRM + 1;
                           
}
                       
}
                   
}

                   
SyncBinding(proposalController.DataContext.ASSET.Current<AssetEntity>()[proposalController.Helper.AssetIndex].
                        PROPOSALRENTALDETAIL
);
               
}
           
}
       
}

   
private void dgStructRental_CellEditEnded(object sender, Telerik.Windows.Controls.GridViewCellEditEndedEventArgs e)
       
{        
               
ValidateProposalRentalTerms();

       
}




 
private proposalProxy.PROPOSALRENTALDETAILInfo AddProposalRentalSlab()
       
{
            proposalProxy
.PROPOSALRENTALDETAILInfo proposalNewRentalSlab =
               
new proposalProxy.PROPOSALRENTALDETAILInfo() { RowState = proposalProxy.DataRowState.Added, RENTALTYP = "AUT" };

           
var proposalRentalDetailColl = proposalController.DataContext.ASSET.Current<proposalProxy.AssetEntity>()[proposalController.Helper.AssetIndex].PROPOSALRENTALDETAIL;

            proposalRentalDetailColl
.Add(proposalNewRentalSlab);

           
if (proposalRentalDetailColl.Count == 1)
           
{
                proposalRentalDetailColl
[proposalRentalDetailColl.Count - 1].STARTTRM = 1;
                proposalRentalDetailColl
[proposalRentalDetailColl.Count - 1].ENDTRM = ContractTerm;
                proposalRentalDetailColl
[proposalRentalDetailColl.Count - 1].RENTALTYP = "AUT";
           
}

           
SyncBinding(proposalRentalDetailColl);
           
return proposalNewRentalSlab;
       
}




 
private void SyncBinding(ObservableCollection<PROPOSALRENTALDETAILInfo> proposalRentalDetails)
       
{

           
int i = 0;
           
for (i = proposalRentalDetails.Count - 1; i >= 0; i--)
           
{
               
if (proposalRentalDetails[i].ENDTRM > ContractTerm)
                  proposalRentalDetails
.MarkRemoved<PROPOSALRENTALDETAILInfo>(i);
           
}
         

           
StructuredRentalViewModel.ProposalRentalDetails = proposalRentalDetails.Current<PROPOSALRENTALDETAILInfo>();
           
this.dgStructRental.ItemsSource = null;
           
//this.dgStructRental.Items.Refresh();
           
this.dgStructRental.ItemsSource = StructuredRentalViewModel.ProposalRentalDetails;
       
}

No answers yet. Maybe you can help?

Tags
GridView
Asked by
mehmood ahmed
Top achievements
Rank 1
Share this question
or