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

In 2010 Q3 New row's cell event does not trigger event

20 Answers 145 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dean Marriott
Top achievements
Rank 1
Dean Marriott asked on 30 Nov 2010, 01:20 AM
Hi,
We had a GridView binded with a data source which works fine in 2009 Q3.  In this grid we are calculating value in a Result Cell based on what user enter in the value Multiplier cell.

Since we updated to 2010 Q3 this is not happening anymore.  We enter the value in Multiplier cell and when we leave the multiplier cell, the Binding Source should fire an event [ListChanged] which calculated the value in result cell.  This event does not fire any more.

However if we leave the row [by clicking the row above] and come back again to new row and we change value in Multiplier then it fires event and calculates the value in Result cell.
  
Q1. How can we achieve this [in 2010 Q3] as now our user just know that they enter a value in multiplier and the moment they leave cell the value will be calculated in the result cell.
Q2. Why the text ['Click here to add a new row] in the bottom of the Grid has disappear.

I have sample project ready to be uploaded but allowed upload file are only Gif, JPEG.  Please let me know if you want our sample project.  

Can someone help us please.  It is now very very urgent.
We were about to release our new version, however it has been halted until we fix Grid issue.  Please help us to fix this problem. 

Aqueel

20 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 30 Nov 2010, 01:01 PM
Hi Dean, 

A sample would be really useful to try and replicate this in the way that you are using it. Whilst you can't upload anything but images here, if you can paste in the code and use the Format Code Block functionality, I'll take a look at it for you. 
Thanks
Richard
0
Dean Marriott
Top achievements
Rank 1
answered on 30 Nov 2010, 10:02 PM
Thanks Richard for reply.  Please note everything was working before we updated to 2010 Q3.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls.UI;
 
namespace GridErrorPrototype
{
     
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
         
 
        private void Form1_Load(object sender, EventArgs e)
        {
            List<GridRecord> list = new List<GridRecord>();
            list.Add(new GridRecord(DateTime.Today,4,2));
            bindingSource1.DataSource = list;
        }
 
        private void bindingSource1_AddingNew(object sender, AddingNewEventArgs e)
        {
            e.NewObject = new GridRecord(DateTime.Today, 0, 2);
        }
 
        private void bindingSource1_ListChanged(object sender, ListChangedEventArgs e)
        {
            //radGridView1.MasterTemplate.Refresh();
             
            if (e.ListChangedType == ListChangedType.ItemChanged)
            {
                var rowIndex = radGridView1.MasterView.ViewTemplate.Rows.IndexOf(radGridView1.CurrentRow);
                GridRecord temp = (GridRecord)radGridView1.CurrentRow.DataBoundItem;
                if(temp!=null)
                    temp.Result = temp.Multiplier * temp.Factor;
            }
        }
 
        
        private void radGridView1_CellValueChanged(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
        {
            var rowIndex = radGridView1.MasterView.ViewTemplate.Rows.IndexOf(radGridView1.CurrentRow);
 
            GridRecord temp = (GridRecord)radGridView1.CurrentRow.DataBoundItem;  //Here I am getting null value as Grid has no Knowledge of new line
            if (e.Column.Name == "column3")
            {
                temp.Result = temp.Multiplier * temp.Factor;
            }
        }
 
         
    }
 
    public class GridRecord
    {
        public GridRecord()
        {
 
        }
        public GridRecord(DateTime date, decimal mul, decimal fac)
        {
            RecordDate = date;
            Multiplier = mul;
            Factor = fac;
            Result = mul * fac;
        }
        public DateTime RecordDate
        {
            get;
            set;
        }
 
        public decimal Multiplier
        {
            get;
            set;
        }
 
        public decimal Factor
        {
            get;
            set;
        }
        public decimal Result
        {
            get;
            set;
        }
    }
}
0
Richard Slade
Top achievements
Rank 2
answered on 30 Nov 2010, 10:29 PM
Hello,

I have tried your sample, but from my tests so far I cannot replicate your issue. Whenever I change the multiplier cell, the value in the result cell updates correctly. Is there a chance in your real application that an event wire up could be missing?

I have added the event wire ups manually here as they weren't included in your sample. I added a radgridview to a form and a binding source. I've added a touch of extra code just for the events and to assign the datasource of the grid. That's it. Please can you try this in a new project and let me know if it's working?

Also, you asked about the add new row text. That was removed by mistake in the Q3 version and I think I am right in saying this is already fixed in the latest internal build which you can download from your product download area.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls.UI;
  
namespace GridErrorPrototype
{
  
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.Load += new System.EventHandler(this.Form1_Load);
            this.bindingSource1.AddingNew += new System.ComponentModel.AddingNewEventHandler(this.bindingSource1_AddingNew);
            this.bindingSource1.ListChanged += new System.ComponentModel.ListChangedEventHandler(this.bindingSource1_ListChanged);
            this.radGridView1.CellValueChanged += new Telerik.WinControls.UI.GridViewCellEventHandler(this.radGridView1_CellValueChanged);
        }
  
  
  
        private void Form1_Load(object sender, EventArgs e)
        {
            this.radGridView1.DataSource = this.bindingSource1;
            List<GridRecord> list = new List<GridRecord>();
            list.Add(new GridRecord(DateTime.Today, 4, 2));
            bindingSource1.DataSource = list;
        }
  
        private void bindingSource1_AddingNew(object sender, AddingNewEventArgs e)
        {
            e.NewObject = new GridRecord(DateTime.Today, 0, 2);
        }
  
        private void bindingSource1_ListChanged(object sender, ListChangedEventArgs e)
        {
            //radGridView1.MasterTemplate.Refresh();
  
            if (e.ListChangedType == ListChangedType.ItemChanged)
            {
                var rowIndex = radGridView1.MasterView.ViewTemplate.Rows.IndexOf(radGridView1.CurrentRow);
                GridRecord temp = (GridRecord)radGridView1.CurrentRow.DataBoundItem;
                if (temp != null)
                    temp.Result = temp.Multiplier * temp.Factor;
            }
        }
  
  
        private void radGridView1_CellValueChanged(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
        {
            var rowIndex = radGridView1.MasterView.ViewTemplate.Rows.IndexOf(radGridView1.CurrentRow);
  
            GridRecord temp = (GridRecord)radGridView1.CurrentRow.DataBoundItem;  //Here I am getting null value as Grid has no Knowledge of new line
            if (e.Column.Name == "column3")
            {
                temp.Result = temp.Multiplier * temp.Factor;
            }
        }
  
  
    }
  
    public class GridRecord
    {
        public GridRecord()
        {
  
        }
        public GridRecord(DateTime date, decimal mul, decimal fac)
        {
            RecordDate = date;
            Multiplier = mul;
            Factor = fac;
            Result = mul * fac;
        }
        public DateTime RecordDate
        {
            get;
            set;
        }
  
        public decimal Multiplier
        {
            get;
            set;
        }
  
        public decimal Factor
        {
            get;
            set;
        }
        public decimal Result
        {
            get;
            set;
        }
    }
}


Hope this helps, but let me know how you get on or if you need further help
Richard
0
Dean Marriott
Top achievements
Rank 1
answered on 30 Nov 2010, 11:12 PM
Thanks again Richard for very quick response.  However I did as you instructed and pasted the code in new project.  The grid behavior is same and error/issue is the same.

I am pasting here where error appears.  I am really surprise why did not error for you.  The error comes up [Null reference exception] because there is no current row in the grid [GridRecord temp = (GridRecord)radGridView1.CurrentRow.DataBoundItem;], therefore I can not multiply the factor and multiplier to put the results in Result column.

I am pasting the event where I encounter the Error.
Please help as it looks to me that Grid and data source are not synchronized.  

Thanks 
Aqueel
private void radGridView1_CellValueChanged(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
        {
            var rowIndex = radGridView1.MasterView.ViewTemplate.Rows.IndexOf(radGridView1.CurrentRow);
 
            GridRecord temp = (GridRecord)radGridView1.CurrentRow.DataBoundItem; 
            //Here I am getting null value as Grid has no Knowledge of new line
            // temp should have value here but it is null
            if (e.Column.Name == "column3")
            {
                temp.Result = temp.Multiplier * temp.Factor;
            }
        }
0
Richard Slade
Top achievements
Rank 2
answered on 30 Nov 2010, 11:23 PM
Hello,

Is this a new error for you? You mentioned before that the event was not being fired. This time, you mention that you have a null reference exception. Again, I have not been able to reproduce any error. I can alter data in the multiplier column, add a new row and leave the values blank.

May I ask which version of the RadControls you are using? for reference, I am using the latest Q3 2010 version.

Look forward to hearing back from you.
Richard
0
Dean Marriott
Top achievements
Rank 1
answered on 30 Nov 2010, 11:47 PM
Hello there again,

It runs perfectly as expected if you make any modification in existing row.  However when you add a new row it does not update Result and factor column.  Here is step by step instruction to see the error/issue.
When program runs and you see the grid,
1. Select a new row and select the date (>>>move to next column [day]).  Please note It update the column with the day.  Now 
2. Enter any number in Multiplier (lets say '5 ' >>> move to next columns [Factor]) Please note nothing happens and it does not update column[Factor] and column [Result].  This is my problem.  What I want to achieve is when I leave column [Multiplier] in newly added row it should update the column Factor and Result in new Row.

Confirming that I am using 2010 Q3.
Aqueel
0
Richard Slade
Top achievements
Rank 2
answered on 01 Dec 2010, 12:17 AM
Hi Dean,

Ok, I see now. Please can you replace your code for BindingSource ListChanged with this and let me know how that looks for you.

private void bindingSource1_ListChanged(object sender, ListChangedEventArgs e)
{
    if (e.ListChangedType == ListChangedType.ItemChanged)
    {
        GridRecord temp = (GridRecord)radGridView1.Rows[e.NewIndex].DataBoundItem;
        if (temp != null)
            temp.Result = temp.Multiplier * temp.Factor;
    }
}

hope that helps
Richard
0
Dean Marriott
Top achievements
Rank 1
answered on 01 Dec 2010, 12:30 AM
Thanks for response but I am sorry to say, it does't solve the problem.  Your suggested code does not update the Factor and Result column unless you click the row above.  Which it was doing before as well.

waiting for your reply.
Aqueel
0
Richard Slade
Top achievements
Rank 2
answered on 01 Dec 2010, 12:40 AM
Hello,

I'm not sure if I understand. Before, if I added a new row and only entered values for the Date and Multiplier, then the result would show as 0, but now if I enter a date and a mutiplier, it correctly shows the result.

Please could you list the steps to reproduce your issue with the new code?
Thanks
Richard
0
Dean Marriott
Top achievements
Rank 1
answered on 01 Dec 2010, 12:58 AM
I have Replaced my code with your given code in [bindingSource1_ListChanged] event.  The problem is still the same.
Here is steps thats what I do;
1. When you are adding the new row, Select a date >>> move to next column [day].  It updates the column with the day. 
2. Enter Multiplier [lets say '10']  >> click Factor, Result or even date cell in the same row.  Nothing happens.  It should update the Result column since we have provided the Multiplier.  It is not updating the Result column.[This is my problem]
3.  I need to update Result column the moment multiplier value has been given and user click any other cell in the newly added row.  I can notice that [bindingSource1_ListChanged] does not get fired until you Select/Click the row above.

Please let me know if I have explained clearly.
0
Richard Slade
Top achievements
Rank 2
answered on 01 Dec 2010, 01:13 AM
Hi,

I'm afraid I'm still not getting your issue.
By the way, there is no day column in the data you have provided.
1: In the new row section, I add a date,
2: tab to the next column, the multiplier
3: Enter a value, say 2
4: Tab to the next column, the factor, leave it blank
5: Tab to the next column, the result, leave it blank
6: Tab again, the row is added

result is:
Date: Date entered
multiplier: 2
factor: 2 (the default when nothing is entered)
result: 4

Regards,
Richard
0
Richard Slade
Top achievements
Rank 2
answered on 01 Dec 2010, 01:18 AM
I've also noticed by the way that you don't need this
private void radGridView1_CellValueChanged(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
{
    var rowIndex = radGridView1.MasterView.ViewTemplate.Rows.IndexOf(radGridView1.CurrentRow);
    GridRecord temp = (GridRecord)radGridView1.CurrentRow.DataBoundItem;  //Here I am getting null value as Grid has no Knowledge of new line
    if (e.Column.Name == "column3")
    {
        temp.Result = temp.Multiplier * temp.Factor;
    }
}
as this example doesn't contain a "column3"
Richard
0
Dean Marriott
Top achievements
Rank 1
answered on 01 Dec 2010, 01:46 AM
Thanks Richard for helping,
Thanks again for picking up the [radGridView1_CellValueChanged] code.  I have already taken this event out.

I think my problem is half solved.  Yes it does calculate the the result if Tab >>Tab until it adds a new row.  
But my user should not have to Tab >> Tab to the last column as I have so many columns and user may not even want to view all these column.  

Ideally ;
1. The moment I enter the date the grid should fill the factor cell [with 2].
2. When I enter Multiplier and move out of the cell [By Clicking any other cell or by Tab] it should update the Result.  
    Currently your suggestion only works if you tab out the last cell [Result] which in response add a new row and updates the result.
Waiting for your next helpful response.

Aqueel
0
Richard Slade
Top achievements
Rank 2
answered on 01 Dec 2010, 02:06 AM
Hello,

The user can also just press Enter after adding in a date, and this will add a new row. The reason why you are not seeing any values here is because the grid is in edit mode and no values are entered or commited to the grid. I will take a look into a way around that for you, but it's not default behavior (if I understand correctly), though it will have to be in the morning now. It's 1am here and I don't think I will be much more use to you tonight!

Until tomorrow.
Richard
0
Dean Marriott
Top achievements
Rank 1
answered on 01 Dec 2010, 03:11 AM
Thanks Richard, I wait for your response until then have good sleep.
Aqueel
0
Richard Slade
Top achievements
Rank 2
answered on 01 Dec 2010, 10:31 AM
Morning,

Please can you try this and let me know if this is what you wanted to do?
Thanks
Richard

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls.UI;
using Telerik.WinControls;
  
namespace GridErrorPrototype
{
  
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.Load += new System.EventHandler(this.Form1_Load);
            this.bindingSource1.AddingNew += new System.ComponentModel.AddingNewEventHandler(this.bindingSource1_AddingNew);
            this.bindingSource1.ListChanged += new System.ComponentModel.ListChangedEventHandler(this.bindingSource1_ListChanged);
            this.radGridView1.CellBeginEdit += new Telerik.WinControls.UI.GridViewCellCancelEventHandler(this.radGridView1_CellBeginEdit);
            this.radGridView1.CellEndEdit += new Telerik.WinControls.UI.GridViewCellEventHandler(this.radGridView1_CellEndEdit);
        }
  
  
  
        private void Form1_Load(object sender, EventArgs e)
        {
            this.radGridView1.DataSource = this.bindingSource1;
            List<GridRecord> list = new List<GridRecord>();
            list.Add(new GridRecord(DateTime.Today, 4, 2));
            bindingSource1.DataSource = list;
        }
  
        private void bindingSource1_AddingNew(object sender, AddingNewEventArgs e)
        {
            e.NewObject = new GridRecord(DateTime.Today, 0, 2);
        }
  
        private void bindingSource1_ListChanged(object sender, ListChangedEventArgs e)
        {
  
            if (e.ListChangedType == ListChangedType.ItemChanged)
            {
                GridRecord temp = (GridRecord)radGridView1.Rows[e.NewIndex].DataBoundItem;
                if (temp != null)
                    temp.Result = temp.Multiplier * temp.Factor;
            }
        }
  
        private void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
        {
            if (e.Column.GetType() == typeof(GridViewDateTimeColumn) && e.RowIndex == -1)
            {
                if (e.Row.Cells["Multiplier"].Value == null)
                {
                   e.Row.Cells["Multiplier"].Value = 2; 
                }
                if (e.Row.Cells["Factor"].Value == null)
                {
                    e.Row.Cells["Factor"].Value = 2;
                }  
            }
        }
  
        private void radGridView1_CellEndEdit(object sender, GridViewCellEventArgs e)
        {
            if (e.RowIndex == -1)
            {
                bool canCalculate = true;
                if (e.Row.Cells["Multiplier"].Value == null)
                {
                    canCalculate = false;
                }
                if (e.Row.Cells["Factor"].Value == null)
                {
                    canCalculate = false;
                }
                if (canCalculate)
                {
                    e.Row.Cells["Result"].Value = Convert.ToDecimal(e.Row.Cells["Multiplier"].Value) * Convert.ToDecimal(e.Row.Cells["Factor"].Value);
                }
            }
        }
  
  
  
    }
  
    public class GridRecord
    {
        public GridRecord()
        {
  
        }
        public GridRecord(DateTime date, decimal mul, decimal fac)
        {
            RecordDate = date;
            Multiplier = mul;
            Factor = fac;
            Result = mul * fac;
        }
        public DateTime RecordDate
        {
            get;
            set;
        }
  
        public decimal Multiplier
        {
            get;
            set;
        }
  
        public decimal Factor
        {
            get;
            set;
        }
        public decimal Result
        {
            get;
            set;
        }
    }
}
0
Richard Slade
Top achievements
Rank 2
answered on 01 Dec 2010, 09:57 PM
Hello Dean,

I hope this has been helpful to you. If it has, please mark all suggestions that you found helpful as answer so others can find the solution too. If you need more help, just let me know.

Thanks
Richard
0
Dean Marriott
Top achievements
Rank 1
answered on 02 Dec 2010, 06:36 AM
Hi Richard,

We are heading in the right direction but still we are not there yet.  I still have some outstanding issues with the grid for.   
As you suggested, I downloaded internal build in the hope that it might fix our problem but this trial build has more problems so I decided to stick to 2010 Q3.
I am so surprise that 2009 Q3 works fine with our existing code but 2010 Q3 does't.
I will upload code to show my unresolved issue by tomorrow. 
Thanks again for help, you being very helpful.

Aqueel
0
Emanuel Varga
Top achievements
Rank 1
answered on 02 Dec 2010, 08:26 AM
Hello Dean,

For the second question, there is a confirmed bug for this issue, a fix was scheduled for the next release.

For the first question, if you can post a project here and i will take a look at it and get back to you.

Best Regards,
Emanuel Varga
Telerik WinForms MVP
0
Richard Slade
Top achievements
Rank 2
answered on 02 Dec 2010, 10:48 AM
Hi All,

Thanks Emanuel, I didn't know that was a reported bug, but the issues reported in this post have been varied, and from what I understand, the version I posted seems to fullfill the requirements.

Dean, please could you try the version I posted and let me know if that works for you. If you need more help, just let me know.
Thanks
Richard

EDIT// Dean, apologies, I didn't see your last post. I'll look forward to seeing your code and we can get this resolved for you.
Richard
Tags
GridView
Asked by
Dean Marriott
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Dean Marriott
Top achievements
Rank 1
Emanuel Varga
Top achievements
Rank 1
Share this question
or