Hi,
I am displaying customer data [Id, Name and Address] in grid view. I also need to display some calculated value “Customer Points” in the grid. For the “Customer Points” I have added a GridViewTextBoxColumn “txtCustomerPoints” to the grid.
For displaying data in “txtCustomerPoints” i am using the CellFormatting Event as below:
private void RadGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
try
{
string columnUniqueName = ((GridViewDataColumn)e.CellElement.ColumnInfo).UniqueName;
if (columnUniqueName == "txtCustomerPoints " )
{
if (IsColumnExistsInGrid(RadGridView1.MasterGridViewTemplate, columnUniqueName))
{
RadGridView1.GridElement.BeginUpdate();
e.CellElement.RowInfo.Cells[columnUniqueName].Value = "Some Calculated Value";
RadGridView1.GridElement.EndUpdate();
}
}
}
catch (Exception ex)
{
throw ex;
}
}
But this generate an error on this line:
e.CellElement.RowInfo.Cells[columnUniqueName].Value = "Some Calculated Value";
The error is:
ex = {"Object reference not set to an instance of an object."}
StackTrace " at MSMainPrj.FormsEmbedded.Booking. RadGridView1_ValueChanging(Object sender, ValueChangingEventArgs e) in D:\\Users\\Yaqub.Ahmad\\CS2\\trunk\\code\\MSMainPrj\\FormsEmbedded\\Booking.cs:line 1755\r\n at Telerik.WinControls.UI.RadGridView.OnValueChanging(Object sender, ValueChangingEventArgs e)\r\n at Telerik.WinControls.UI.RadGridView.CallValueChanging(Object sender, ValueChangingEventArgs e)\r\n at Telerik.WinControls.UI.GridViewCellInfo.set_Value(Object value)\r\n at MSMainPrj.Libraries.TelerikGridHelper.SetGridColumnValue(RadGridView grid, CellFormattingEventArgs e, String columnName, Object value) in D:\\Users\\Yaqub.Ahmad\\CS2\\trunk\\code\\MSMainPrj\\Libraries\\TelerikGridHelper.cs:line 292" string
TargetSite {Void RadGridView1_ValueChanging(System.Object, Telerik.WinControls.UI.ValueChangingEventArgs)} System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}
Kindly help me to update a custom column's value.
Thanks.