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

[Solved] GridView CellEditEnded returns null data properties for custom column.

5 Answers 299 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Amit Patel
Top achievements
Rank 1
Amit Patel asked on 06 Jan 2010, 08:24 PM
I have a extended custom column which I creates at run time and set the data source on each cell. Since the data source is not always same I will have to set that at the cell level. However, when i am editing any of these cells the grids CellEditEnded event is fired, but the e.OldData and e.NewData properties of GridViewCellEditEndedEventArgs are always null. Does anyone know what i am missing here in the code? Thanks,
-------------
Code

public

 

class ExtendedGridViewDataColumn : GridViewDataColumn

 

{

 

#region

 

"Properties"

 

 

public int Index { get; set; }

 

 

public int DataType { get; set; }

 

#endregion

 

 

#region

 

"Methods"

 

 

public override FrameworkElement CreateCellElement(GridViewCell cell, object dataItem)

 

{

 

FrameworkElement cellElement = null;

 

 

TextBlock textBlock = new TextBlock();

 

 

Binding binding = new Binding();

 

 

string valueProperty = GetPropertyNameForEditorType();

 

 

if (((AttributeDataType)DataType)== AttributeDataType.Date)

 

{

SetBindingProperties(binding, valueProperty,

true);

 

binding.Converter =

new DateTimeConverter();

 

textBlock.SetBinding(

TextBlock.TextProperty, binding);

 

}

 

else

 

{

SetBindingProperties(binding, valueProperty,

false);

 

textBlock.SetBinding(

TextBlock.TextProperty, binding);

 

}

cellElement = textBlock;

 

return cellElement;

 

}

 

public override FrameworkElement CreateCellEditElement(GridViewCell cell, object dataItem)

 

{

 

FrameworkElement cellEditElement = null;

 

 

string valueProperty = GetPropertyNameForEditorType();

 

 

Binding binding = new Binding();

 

 

switch ((AttributeDataType)DataType)

 

{

 

case AttributeDataType.Text:

 

{

cellEditElement =

this.CreateTextEditor(binding, valueProperty);

 

 

break;

 

}

 

case AttributeDataType.Flag:

 

{

cellEditElement =

this.CreateCheckBoxEditor(binding, valueProperty);

 

 

break;

 

}

 

case AttributeDataType.Date:

 

{

cellEditElement =

this.CreateDateTimeEditor(binding, valueProperty);

 

 

break;

 

}

 

default:

 

{

cellEditElement =

this.CreateTextEditor(binding, valueProperty);

 

 

break;

 

}

}

 

return cellEditElement;

 

}

 

private FrameworkElement CreateCheckBoxEditor(Binding binding, string valueProperty)

 

{

 

CheckBox checkBox = new CheckBox();

 

SetBindingProperties(binding, valueProperty,

true);

 

checkBox.SetBinding(

CheckBox.IsCheckedProperty, binding);

 

checkBox.Loaded +=

this.Editor_Loaded;

 

 

return checkBox;

 

}

 

private FrameworkElement CreateDateTimeEditor(Binding binding, string valueProperty)

 

{

 

RadDatePicker datePicker = new RadDatePicker();

 

SetBindingProperties(binding, valueProperty,

true);

 

binding.Converter =

new DateTimeConverter();

 

datePicker.SetBinding(

RadDatePicker.SelectedDateProperty, binding);

 

datePicker.Loaded +=

this.Editor_Loaded;

 

 

return datePicker;

 

}

 

private FrameworkElement CreateTextEditor(Binding binding, string valueProperty)

 

{

 

TextBox textBox = new TextBox();

 

SetBindingProperties(binding, valueProperty,

true);

 

textBox.SetBinding(

TextBox.TextProperty, binding);

 

textBox.Loaded +=

this.textBox_Loaded;

 

 

return textBox;

 

}

 

private static void SetBindingProperties(Binding valueBinding, string propertyName, bool twoway)

 

{

 

if (twoway)

 

{

valueBinding.Mode =

BindingMode.TwoWay;

 

}

 

else

 

{

valueBinding.Mode =

BindingMode.OneWay;

 

}

valueBinding.Path =

new PropertyPath(propertyName);

 

valueBinding.NotifyOnValidationError =

true;

 

valueBinding.ValidatesOnExceptions =

true;

 

}

 

private string GetPropertyNameForEditorType()

 

{

 

string propertyName;

 

 

switch ((AttributeDataType)DataType)

 

{

 

case AttributeDataType.Number:

 

{

propertyName =

"Number";

 

 

break;

 

}

 

case AttributeDataType.Flag:

 

{

propertyName =

"Flag";

 

 

break;

 

}

 

case AttributeDataType.Date:

 

{

propertyName =

"Date";

 

 

break;

 

}

 

default:

 

{

propertyName =

"Text";

 

 

break;

 

}

}

 

return propertyName;

 

}

#endregion

#region

 

"Events"

 

 

void Editor_Loaded(object sender, RoutedEventArgs e)

 

{

 

Control target = sender as Control;

 

 

if (target != null)

 

{

target.Focus();

}

}

 

void textBox_Loaded(object sender, RoutedEventArgs e)

 

{

 

var textBox = (sender as TextBox);

 

 

if (textBox != null)

 

{

textBox.Focus();

textBox.SelectAll();

}

}

#endregion

}

5 Answers, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 07 Jan 2010, 09:15 AM
Hi Amit Patel,

At first glance everything looks fine with your custom column. I suppose that the problem is the integration with the RadGridView and especially with the way you set the data source to each cell. Can you send me a sample project which I can debug on my side?

Best wishes,
Nedyalko Nikolov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Amit Patel
Top achievements
Rank 1
answered on 15 Jan 2010, 04:17 PM
Thanks Nedyalko!!

I was just wondering if you got my sample project, and had time to take look into issue. I replied to your email with attached zip file of the project since i could not attached the project here. The forum will only allow image files to be attached.

Thanks,
Amit
0
Nedyalko Nikolov
Telerik team
answered on 18 Jan 2010, 02:01 PM
Hi Amit Patel,

Please open a support ticket and attach the project, since our mail system blocks e-mails with zip as attachment.
Sorry for the inconvenience caused.

Greetings,
Nedyalko Nikolov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Amit Patel
Top achievements
Rank 1
answered on 18 Jan 2010, 02:29 PM
Nedyalko,
I have opened up the ticket # 274124.
Thanks,
Amit
0
Nedyalko Nikolov
Telerik team
answered on 19 Jan 2010, 09:42 AM
Hi Amit Patel,

Following is my answer to your support ticket, since your support ticket is not available for the members of Telerik community.

There is a fix only for the "OldData" part, this value is bound to the GridViewCell value, so you can set binding to the GridViewCell.Value property within the CreateCellElement method:

cell.SetBinding(GridViewCell.ValueProperty, CreateValueBinding(valueProperty, false));

Unfortunately we cannot fix the "NewData" part with 2009.Q2 version. This behavior can be easily achieved with the last version as shown in my example. Otherwise you can get the GridViewCell object from the event args and get the required information from the editor inside. You can use code similar to get the new value:

e.Cell.ChildrenOfType<TextBox>()[0].Text


Greetings,
Nedyalko Nikolov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Amit Patel
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
Amit Patel
Top achievements
Rank 1
Share this question
or