public static void RemoveDynamicColumns(ColumnView gridView, IDynamicPropertyList propertyList)
        {
            gridView.BeginDataUpdate();

            foreach (IDynamicProperty p in propertyList.GetProperties(true))
            {
                GridColumn foundColumn = null;

                foreach (GridColumn column in gridView.Columns)
                {
                    if (column.Tag != null)
                    {
                        var keyValue = column.Tag as string;

                        if (keyValue != null)
                        {
                            if (keyValue == p.Key)
                            {
                                foundColumn = column;
                            }
                        }
                    }
                }

                if (foundColumn != null)
                {
                    gridView.Columns.Remove(foundColumn);
                    foundColumn.Dispose();
                }
            }
            gridView.EndDataUpdate();
        }
        private static void AddDynamicColumns(ColumnView gridView, IDynamicPropertyList propertyList, ESortBy sortBy,
                                              ESortDirection sortDir, string nullText, IComparer <IDynamicProperty> comparer, bool allowFilter)
        {
            RepositoryItemTextEdit riteCol = null;

            gridView.BeginDataUpdate();
            int visibleIndexValue = 0;

            foreach (GridColumn column in gridView.Columns)
            {
                if (column.VisibleIndex > visibleIndexValue)
                {
                    visibleIndexValue = column.VisibleIndex;
                }
            }

            if (!string.IsNullOrEmpty(nullText))
            {
                riteCol          = new RepositoryItemTextEdit();
                riteCol.NullText = nullText;
            }

            List <IDynamicProperty> propertyListSorted;

            if (comparer == null)
            {
                propertyListSorted = propertyList.GetPropertiesSorted(true, sortBy, sortDir);
            }
            else
            {
                propertyListSorted = propertyList.GetPropertiesSorted(true, comparer);
            }

            foreach (IDynamicProperty property in propertyListSorted)
            {
                var newColumn = new GridColumn();

                newColumn.Caption   = property.DisplayName;
                newColumn.FieldName = property.Key;
                newColumn.Name      = "col" + property.Key;
                newColumn.OptionsColumn.ReadOnly = property.ReadOnly;
                newColumn.Visible = property.Visible;
                newColumn.ToolTip = property.Description;
                newColumn.OptionsFilter.AllowFilter = allowFilter;
                if (riteCol != null)
                {
                    newColumn.ColumnEdit = riteCol;
                }

                if (property.Visible)
                {
                    visibleIndexValue++;
                    newColumn.VisibleIndex = visibleIndexValue;
                }
                else
                {
                    newColumn.VisibleIndex = -1;
                }

                newColumn.Tag         = property.Key;
                newColumn.UnboundType = GetUnboundType(property);

                //check if column exists
                foreach (GridColumn column in gridView.Columns)
                {
                    Debug.Assert(column.Name != newColumn.Name, "Column with this name exists already");
                }

                gridView.Columns.Add(newColumn);
            }
            gridView.EndDataUpdate();
        }