Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,
I am Working on Windows Form Telerik.
As I have Grid View of Telerik Control and i want to add New Entry into that.
I have Button for create new Entry Click on that button Winform will popup and on that popup if i click on save it will add that row.
But My Problem is that 1 Row added with that another Row also add which is not required.

My Code Is Below.


C#
public void Save(TimesheetEntry timesheetEntry)
      {
          if (timesheetEntry.TimesheetEntriesId == -1)
          {
              timesheetEntry.SequenceNumber = GetNextSequenceNumber(timesheetEntry.FileId, timesheetEntry.EntryDate);
              Add(timesheetEntry);

          }
          else
          {
              Update(timesheetEntry);
          }
          //Audit trail
          //TODO:
          //MyAuditTrialModel.Add<TimesheetEntry>(Helper.Actions.CU_Timesheet, Helper.TableNames.TimesheetEntry, timesheetEntry);
      }




C#
private TimesheetEntry Add(TimesheetEntry item)
       {
           _context.TimesheetEntries.AddObject(item);
           _context.SaveChanges();
           return item;
       }




And On Edit Button also it will Generate 2 rows.
which code is as below.

C#
private TimesheetEntry Update(TimesheetEntry item)
       {
           _context.TimesheetEntries.ApplyChanges(item);
           _context.ObjectStateManager.ChangeObjectState(item, System.Data.EntityState.Modified);
           _context.SaveChanges(true);
           return item;
       }





plz help me to resolve this issue.

Thanks
Posted
Comments
Sinisa Hajnal 27-Feb-15 2:47am    
Put a breakpoint on Add and start going into code until you find which part is being called twice.
dlpanchal 27-Feb-15 4:09am    
i have checked that but at that time calling add and till complete there is only one time called and entry also added only once.
but when it will return to Grid than in Grid i find 2 entries.
dlpanchal 27-Feb-15 7:51am    
hello, can somebody help me to overcome this issue..
Sinisa Hajnal 28-Feb-15 2:31am    
If you're adding to the source programmatically, remove the property that says that a user can add new rows. Otherwise you get one for auto add and another from your own code. I hope this helps, I don't see anything wrong with your code.
dlpanchal 2-Mar-15 8:19am    
thanks for your view on that but still its not solved.
but actually there is not any property through which user can add new entry.
and there is Entity through which new one is added so how its possible to add another one.

and in some other page its work as required with this same code for add.
but here it is problem arises.

plz help to overcome from this


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900