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

custom insert new row

1 Answer 107 Views
GridView
This is a migrated thread and some comments may be shown as answers.
ronald
Top achievements
Rank 1
ronald asked on 18 Jan 2011, 01:40 AM
Hi,

Assume you have a class (say ClassA). ClassA inherits from another class (say ClassB) which contains property of DataRow (_data).

Now when the itemssource of RadGridView binds to ClassA and the user creates a new row, RadGridview will only create a new class of ClassA but it does not create the DataRow (_data) propery. How can I make the _data property is generated while creating a new row? thanks

public class ClassB: INotifyPropertyChanged
    {
        #region Data
        DataRow _data;
 
        [Browsable(false), Bindable(false)]
        public DataRow DataRow
        {
            get { return _data; }
            set { _data = value; OnPropertyChanged("DataRow"); }
        }
        #endregion // Data
 
        #region Constructors
 
        protected ClassB(DataRow data)
            : this()
        {
            _data = data;
        }
        protected ClassB()
        {
             
        }
        #endregion // Constructors
 
 
        public object GetField(string name)
        {
            object value = null;
            try
            {
                if (_data.Table.Columns.Contains(name))
                {
                    value = _data[name];
                    if (value is DBNull)
                        value = null;
                }
                else
                    value = null;
            }
            catch { }
            return value;
        }
        public void SetField(string name, object value)
        {
            try
            {
                if (_data.Table.Columns.Contains(name))
                {
                    _data[name] = (value == null) ? DBNull.Value : value;
                }
            }
            catch {}
        }
 
        #region INotifyPropertyChanged Members
 
        public event PropertyChangedEventHandler PropertyChanged;
 
        protected virtual void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
 
        #endregion // INotifyPropertyChanged Members
    }

1 Answer, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 18 Jan 2011, 08:24 AM
Hello,

Why not create default value for this property in your class constructor? 

Greetings,
Vlad
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
GridView
Asked by
ronald
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or