BrightIdeasSoftware.ObjectListView.GetFilteredColumns C# (CSharp) Method

GetFilteredColumns() public method

Return a collection of columns that are visible to the given view. Only Tile and Details have columns; all other views have 0 columns.
public GetFilteredColumns ( View view ) : List
view View Which view are the columns being calculate for?
return List
        public virtual List<OLVColumn> GetFilteredColumns(View view)
        {
            // For both detail and tile view, the first column must be included. Normally, we would
            // use the ColumnHeader.Index property, but if the header is not currently part of a ListView
            // that property returns -1. So, we track the index of
            // the column header, and always include the first header.

                    int index = 0;
                    return this.AllColumns.FindAll(delegate(OLVColumn x) {
                        return (index++ == 0) || x.IsVisible;
                    });
        }

Usage Example

        /// <summary>
        /// Edit a given value
        /// </summary>
        /// <param name="context"></param>
        /// <param name="provider"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            // Figure out which ObjectListView we are working on. This should be the Instance of the context.
            ObjectListView olv = null;

            if (context != null)
            {
                olv = context.Instance as ObjectListView;
            }

            if (olv == null)
            {
                //THINK: Can this ever happen?
                System.Diagnostics.Debug.WriteLine("context.Instance was NOT an ObjectListView");

                // Hack to figure out which ObjectListView we are working on
                ListView.ColumnHeaderCollection cols = (ListView.ColumnHeaderCollection)value;
                if (cols.Count == 0)
                {
                    cols.Add(new OLVColumn());
                    olv = (ObjectListView)cols[0].ListView;
                    cols.Clear();
                    olv.AllColumns.Clear();
                }
                else
                {
                    olv = (ObjectListView)cols[0].ListView;
                }
            }

            // Edit all the columns, not just the ones that are visible
            base.EditValue(context, provider, olv.AllColumns);

            // Calculate just the visible columns
            List <OLVColumn> newColumns = olv.GetFilteredColumns(View.Details);

            olv.Columns.Clear();
            olv.Columns.AddRange(newColumns.ToArray());

            return(olv.Columns);
        }
ObjectListView