private void CollapseChildren(GridItem gi)
        {
            if (gi == null)
            {
                return;
            }
            foreach (GridItem currentItem in gi.GridItems)
            {
                PropertyDescriptor desc = currentItem.PropertyDescriptor;
                PropertyModelView.OptionItemPropertyDescriptor item = desc as PropertyModelView.OptionItemPropertyDescriptor;
                if (item != null)
                {
                    bool oldState;
                    bool existed = collapseState.TryGetValue(item.FullyQualifiedName, out oldState);
                    if (existed)
                    {
                        currentItem.Expanded = oldState;
                        CollapseChildren(currentItem);
                    }
                    else
                    {
                        object attr = item.GetAttribute(TableEditorFactory.RENDERING_HINTS_ATTRIBUTE);
                        if (attr != null)
                        {
                            TableEditorFactory.RenderingHints attrValue = (TableEditorFactory.RenderingHints)attr;
                            if ((attrValue & TableEditorFactory.RenderingHints.Collapsed) == TableEditorFactory.RenderingHints.Collapsed)
                            {
                                currentItem.Expanded = false;
                            }
                            else
                            {
                                currentItem.Expanded = true;
                                //scan all children
                                CollapseChildren(currentItem);
                            }
                        }
                        else
                        {
                            currentItem.Expanded = true;
                            //scan all children
                            CollapseChildren(currentItem);
                        }
                    }
                }
                else
                {
                    currentItem.Expanded = true;
                    //scan all children
                    CollapseChildren(currentItem);
                }
            }
//      if(gi.GridItems.Count > 0) {
//        collapseState.Clear();
//      }
        }
        /// <summary>
        /// Configures additional attributes for an option item or option group, such as collapsed state and group visibility.
        /// </summary>
        /// <param name="item">The item or group to configure.</param>
        /// <param name="propertyInfo">The associated property info.</param>
        protected virtual void ConfigureItem(IOptionItem item, PropertyInfo propertyInfo)
        {
            TableEditorFactory.RenderingHints   tableRenderingHints   = TableEditorFactory.RenderingHints.Collapsed;
            DefaultEditorFactory.RenderingHints defaultRenderingHints = DefaultEditorFactory.RenderingHints.Invisible;
            ItemRenderingHintsAttribute         hintsAttribute        =
                (ItemRenderingHintsAttribute)Attribute.GetCustomAttribute(propertyInfo, typeof(ItemRenderingHintsAttribute));

            if (hintsAttribute != null)
            {
                tableRenderingHints   = hintsAttribute.TableRenderingHints;
                defaultRenderingHints = hintsAttribute.DialogRenderingHints;
            }
            item.SetAttribute(TableEditorFactory.RENDERING_HINTS_ATTRIBUTE, tableRenderingHints);
            item.SetAttribute(DefaultEditorFactory.RENDERING_HINTS_ATTRIBUTE, defaultRenderingHints);

            NullableAttribute nullableAttribute =
                (NullableAttribute)Attribute.GetCustomAttribute(propertyInfo, typeof(NullableAttribute));

            if (nullableAttribute != null)
            {
                item.SetAttribute(OptionItem.SUPPORT_NULL_VALUE_ATTRIBUTE, nullableAttribute.IsNullable);
            }

            DescriptionAttribute attribute = GetAttribute <DescriptionAttribute>(propertyInfo);

            if (attribute != null && !attribute.IsDefaultAttribute())
            {
                item.SetAttribute(OptionItem.DESCRIPTION_ATTRIBUTE, attribute.Description);
            }

            var customAttributes = Attribute.GetCustomAttributes(propertyInfo);

            foreach (var attrib in customAttributes.OfType <OptionItemAttributeAttribute>())
            {
                item.SetAttribute(attrib.Name, attrib.Value);
            }
        }