This question is locked. New answers and comments are not allowed.
hi,
i have a problem with the editor functionallity of the GridView.
when i create a GridView and put cells in of value type of Object by TwoWay-binding and when the objects contains non-string values, after editing the cells inside the gridView the object type of the value is from type String.
here is my GridView definition...
... my item element definition
... and here are some test items
e.g.: if i try to edit the Value-cell of the "my Decimal" item, after editing the value is from type String.
but i want to have a value of the same type.
i tried to buld an Converter that will convert the string in its wanted value types, but than i have the problem that the TargetType is always from type Object - so i don't know inside the converter to what type i really want to convert the value.
i tried to bind the ConverterParameter to "ValueType" of the item, to see the wanted type inside the Converter, but the Binding throws an InvalidOperationException.
i tried to handle the gridView.CellValidating event, but i am not able to change the value of NewValue (is readonly), and IsValid & IsHandled will only affecting the commitment of the value that comes from the EditorPresenter(?).
i tried to handle the gridView.PreparingCellForEdit event, to apply an other EditorPresenter for the current cell, but there are no information what for this event is - i don't found any information about this event. on the way, i don't think that these is the correct place to adjust the editor of the cell...
i also tried to make an ListElement<T> (ListElement<Int32>, ListElement<Int16>, ListElement<Decimal>, ... with public <T> Value{} ), but than i cannot build an
i have a problem with the editor functionallity of the GridView.
when i create a GridView and put cells in of value type of Object by TwoWay-binding and when the objects contains non-string values, after editing the cells inside the gridView the object type of the value is from type String.
here is my GridView definition...
<telerik:RadGridView x:Name="gridView" CanUserFreezeColumns="False" AutoGenerateColumns="False" ShowGroupPanel="False" RowIndicatorVisibility="Collapsed" > <telerik:RadGridView.Columns> <telerik:GridViewDataColumn Header="Param" DataMemberBinding="{Binding Param}" IsFilterable="False" IsReadOnly="True"/> <telerik:GridViewDataColumn Header="Value" IsFilterable="False" IsReadOnly="False" EditTriggers="CurrentCellClick"> <telerik:GridViewDataColumn.DataMemberBinding> <Binding Path="Value" Mode="TwoWay" /> </telerik:GridViewDataColumn.DataMemberBinding> </telerik:GridViewDataColumn> </telerik:RadGridView.Columns> </telerik:RadGridView> ... my item element definition
public class ListElement : INotifyPropertyChanged { #region Param Property public string Param { get; set; } #endregion #region Value Property public const string ValuePropertyName = "Value"; public object ValueField; public object Value { get { return ValueField; } set { object oldValue = ValueField; object newValue = value; if (!object.ReferenceEquals(oldValue, newValue)) { ValueField = newValue; RaisePropertyChanged(ValuePropertyName); } } } #endregion #region ValueType Property public Type ValueType { get; set; } #endregion public ListElement(string param, object value) { this.Param = param; this.Value = value; if (value != null) this.ValueType = value.GetType(); } #region INotifyPropertyChanged Members public event PropertyChangedEventHandler PropertyChanged; private void RaisePropertyChanged(string propertyName) { PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) { PropertyChangedEventArgs args = new PropertyChangedEventArgs(propertyName); handler(this, args); } } #endregion } ... and here are some test items
{ ObservableCollection<ListElement> data = new ObservableCollection<ListElement>(); data.Add(new ListElement("my Int32", (Int32)123)); data.Add(new ListElement("my Int16", (Int16)12)); data.Add(new ListElement("my Decimal", (Decimal)123.45M)); data.Add(new ListElement("my Double", (Double)123.456)); data.Add(new ListElement("my String", (String)"ABCDEF")); this.gridView.ItemsSource = data; }e.g.: if i try to edit the Value-cell of the "my Decimal" item, after editing the value is from type String.
but i want to have a value of the same type.
i tried to buld an Converter that will convert the string in its wanted value types, but than i have the problem that the TargetType is always from type Object - so i don't know inside the converter to what type i really want to convert the value.
i tried to bind the ConverterParameter to "ValueType" of the item, to see the wanted type inside the Converter, but the Binding throws an InvalidOperationException.
i tried to handle the gridView.CellValidating event, but i am not able to change the value of NewValue (is readonly), and IsValid & IsHandled will only affecting the commitment of the value that comes from the EditorPresenter(?).
i tried to handle the gridView.PreparingCellForEdit event, to apply an other EditorPresenter for the current cell, but there are no information what for this event is - i don't found any information about this event. on the way, i don't think that these is the correct place to adjust the editor of the cell...
i also tried to make an ListElement<T> (ListElement<Int32>, ListElement<Int16>, ListElement<Decimal>, ... with public <T> Value{} ), but than i cannot build an
ObservableCollection<ListElement<T>> data = new ObservableCollection<ListElement<T>>();
does anybody has an idea, how i can specify the kind of cell editing if the targetType of the cell is from type Object?