Exemple #1
0
        public void AddField(IListViewField Field)
        {
            ListViewFieldAdapter Adapter = new ListViewFieldAdapter();

            Adapter.Field       = Field;
            Adapter.Column      = new ColumnHeader();
            Adapter.Column.Text = Field.DisplayName;
            Adapter.Column.Name = Field.GetType().Name;

            int                    field_width    = Field.InitialWidth;
            FieldWidthStyle        width_style    = Field.InitialWidthStyle;
            ListViewColumnSettings field_settings = null;

            if (mSettings != null)
            {
                field_settings = mSettings.GetColumnSettings(
                    Adapter.Column, Field.InitialWidthStyle, Field.InitialWidth);
                field_width = field_settings.Width;
                width_style = field_settings.WidthStyle;
            }

            Adapter.Column.Width = ComputeColumnWidth(width_style, field_width);

            mFields.Add(Adapter);
            if (field_settings == null || field_settings.Visible)
            {
                Adapter.Column.DisplayIndex = mFields.Count + 1;
                Columns.Add(Adapter.Column);
            }
        }
Exemple #2
0
        void ListViewEx_HandleCreated(object sender, EventArgs e)
        {
            mHeaderContextMenuStrip = new ContextMenuStrip();

            foreach (ColumnHeader header in mFields.Select(x => x.Column))
            {
                ToolStripMenuItem      item            = new ToolStripMenuItem(header.Text);
                ListViewColumnSettings column_settings =
                    (mSettings == null) ? null : mSettings.Columns[header.Name];
                item.Checked = (column_settings == null) || column_settings.Visible;

                item.CheckOnClick = true;
                item.Tag          = new ToolStripItemTag
                {
                    Header    = header,
                    LastIndex = header.DisplayIndex,
                    LastWidth = (mSettings == null)
                              ? header.Width
                              : ComputeColumnWidth(column_settings.WidthStyle, column_settings.Width)
                };
                item.CheckStateChanged += item_CheckStateChanged;
                mHeaderContextMenuStrip.Items.Add(item);
            }
        }