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

Some RadGrid Rows becoming Readonly in edit mode.

0 Answers 29 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Geo
Top achievements
Rank 1
Geo asked on 01 Feb 2012, 10:45 AM

I have a custom GridView inherited from ‘RadGridView’ which is binded to generic list.

Some of the rows in the gridview is becoming readonly(Edited values are getting restored to older value when curser moved to next position) while editing(not all rows).

Please help

Custom grid view

------------

public enum EquipmentList

    {

        Unknown,

        StowList,

        DischargeList,

        RestowList,

        HandList,

        StowedList,

        ProcessList

    }

   

    public class EquipmentsGridView : RadGridView

    {

        public EquipmentList ListType { get; set; }

        private ObservableCollection<EquipmentInformation> _source;

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "By design")]

        public IList<EquipmentInformation> Source

        {

            get

            {

                return _source;

            }

            set

            {

                if (_source != null)

                {

                    _source.CollectionChanged -= new System.Collections.Specialized.NotifyCollectionChangedEventHandler(_source_CollectionChanged);

                }

                base.ItemsSource = _source = new ObservableCollection<EquipmentInformation>(value);

                _source.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(_source_CollectionChanged);

                ResetNumbers();

                ApplyBehavior();

            }

        }

        public bool IsEdited { get; set; }

        public EquipmentsGridView()

        {

            base.CellValidating += GridView_CellValidating;

            base.SelectionChanged += new EventHandler<SelectionChangeEventArgs>(EquipmentsGridView_SelectionChanged);

        }

        void EquipmentsGridView_SelectionChanged(object sender, SelectionChangeEventArgs e)

        {

            if (this.Items.IsAddingNew || this.Items.IsEditingItem)

            {

                this.CommitEdit();

            }

        }

        private void ApplyBehavior()

        {

            foreach (var column in base.Columns)

            {

                if (column is GridViewBoundColumnBase)

                {

                    column.ShowDistinctFilters = false;                

                }

            }

        }

        void EquipmentsGridView_CellValidated(object sender, GridViewCellValidatedEventArgs e)

        {

            if (e.Cell.ParentRow.Item != null)

            {

                if (((EquipmentInformation)e.Cell.ParentRow.Item).IsCanceled)

                {

                    e.Cell.Foreground = Brushes.White;

                    e.Cell.Background = Brushes.Red;

                    e.Cell.FontStyle = FontStyles.Oblique;

                }

                else

                {

                    e.Cell.Foreground = Brushes.Black;

                    e.Cell.Background = Brushes.White;

                    e.Cell.FontStyle = FontStyles.Normal;

                }

            }

        }

        void _source_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)

        {

            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add ||

                e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove ||

                e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Reset)

            {

                ResetNumbers();

                IsEdited = true;

            }

        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase", Justification = "Editing need to be in lowercase")]

        private void GridView_CellValidating(object sender, Telerik.Windows.Controls.GridViewCellValidatingEventArgs e)

        {

            if (e.OldValue != e.NewValue)

            {

                ((System.Windows.Controls.TextBox)(e.EditingElement)).Text = e.NewValue.ToString().ToLower(System.Globalization.CultureInfo.InvariantCulture);

                IsEdited = true;

            }

        }

    }

No answers yet. Maybe you can help?

Tags
GridView
Asked by
Geo
Top achievements
Rank 1
Share this question
or