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

NumericColumn for RadGridView and Integer values

5 Answers 119 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Szymon Wantuch
Top achievements
Rank 1
Szymon Wantuch asked on 26 May 2010, 05:22 PM
I am trying to implement simple NumericColumn using RadNumericUpDown. The problem is that value of the Numeric does not get updated if I bind it to integer property. Binding to decimal works great.

Here's my source code:
    public class NumericColumn : GridViewBoundColumnBase  
    {  
        public bool IsInteger  
        {  
            get { return (bool)GetValue(IsIntegerProperty); }  
            set { SetValue(IsIntegerProperty, value); }  
        }  
          
        public static readonly DependencyProperty IsIntegerProperty =  
            DependencyProperty.Register("IsInteger"typeof(bool), typeof(NumericColumn), null);  
         
        public override FrameworkElement CreateCellEditElement(GridViewCell cell, object dataItem)  
        {  
            this.BindingTarget = RadNumericUpDown.ValueProperty;  
            var numeric = new RadNumericUpDown();  
            numeric.IsInteger = this.IsInteger;  
            numeric.SetBinding(this.BindingTarget, this.CreateValueBinding());  
            return numeric;  
        }  
 
        private Binding CreateValueBinding()  
        {  
            var valueBinding = new Binding();  
            valueBinding.Mode = BindingMode.TwoWay;  
            valueBinding.NotifyOnValidationError = true;  
            valueBinding.ValidatesOnExceptions = true;  
            valueBinding.UpdateSourceTrigger = UpdateSourceTrigger.Explicit;  
            valueBinding.Path = new PropertyPath(this.DataMemberBinding.Path.Path);  
            return valueBinding;  
        }          
    } 

I am using the RadControls for Silverlight Q1 2010 SP1 Relese.

Sincerely,
Szymon Wantuch


5 Answers, 1 is accepted

Sort by
0
Yordanka
Telerik team
answered on 27 May 2010, 09:40 AM
Hello Szymon Wantuch,

Please, find the attached project where we have made some changes about your NumericColumn in order to achieve desired behavior. I hope this will help.

If you have any other questions do not hesitate to contact us.

Best wishes,
Yordanka
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Szymon Wantuch
Top achievements
Rank 1
answered on 27 May 2010, 01:40 PM

Thank you for the answer. The provided example solved the problem.

However, I've noticed a problem in the insert row of the grid. When I insert new row, edit value inside numeric, and press tab, then after losing focus the value is still 0. After commiting the row insert, the values display are correct. It seems that the new value is commited to the property but is incorrectly displayed.

The problem happens only in the grids where the data source for the row is the ViewModel containg Model class, wrapping it and accessing it's properties. It doesn't happen in other grids. I doesn't also happen during normal editing in grid, just only in the InsertRow.

Below is the example of the way the datasource is implemented, not the class itself:

 public class ModelClass : INotifyPropertyChanged  
    {  
        private string _name;  
        public string Name  
        {  
            get { return _name; }  
            set 
            {  
                if (_name != value)  
                {  
                    _name = value;  
                    OnPropertyChanged("Name");  
                }  
            }  
        }  
 
        protected void OnPropertyChanged(string propertyName)  
        {  
            if (this.PropertyChanged != null)  
            {  
                PropertyChanged(thisnew PropertyChangedEventArgs(propertyName));  
            }  
        }  
 
        public event PropertyChangedEventHandler PropertyChanged;  
    }  
 
    public class ItemViewModel : INotifyPropertyChanged  
    {  
        public ModelClass Item { getprivate set; }  
 
        public ItemViewModel()  
            : this(new ModelClass())  
        {  
 
        }  
 
        public ItemViewModel(ModelClass item)  
        {  
            this.Item = item;  
        }  
          
        public string Name  
        {  
            get { return Item.Name; }  
            set 
            {  
                if (Item.Name != value)  
                {  
                    Item.Name = value;  
                    OnPropertyChanged("Name");  
                }  
            }  
        }          
 
        protected void OnPropertyChanged(string propertyName)  
        {  
            if (this.PropertyChanged != null)  
            {  
                PropertyChanged(thisnew PropertyChangedEventArgs(propertyName));  
            }  
        }  
 
        public event PropertyChangedEventHandler PropertyChanged;  
    } 

Sincerely,
Szymon Wantuch

0
Milan
Telerik team
answered on 28 May 2010, 07:50 AM
Hi Szymon Wantuch,

If you could send us your sample application we will try to resolve the issue as soon as possible.


Sincerely yours,
Milan
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Szymon Wantuch
Top achievements
Rank 1
answered on 01 Jun 2010, 08:41 AM
I've attached the sample in the support ticket 314677.

Best Regards,
Szymon Wantuch
0
Accepted
Milan
Telerik team
answered on 01 Jun 2010, 10:44 AM
Hello Szymon Wantuch,

Thank you for sending us the sample project. One of my colleagues has already posted an answer to the support thread.


Kind regards,
Milan
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
Szymon Wantuch
Top achievements
Rank 1
Answers by
Yordanka
Telerik team
Szymon Wantuch
Top achievements
Rank 1
Milan
Telerik team
Share this question
or