예제 #1
0
        protected override void OnColumnAdded(DataGridViewColumnEventArgs e)
        {
            base.OnColumnAdded(e);
            IBindingView bindingView = DataSource as IBindingView;

            if (bindingView != null)
            {
                PropertyInfo[] propDesc = bindingView.UnderlyingType.GetProperties();
                foreach (PropertyInfo prop in propDesc)
                {
                    if (e.Column.HeaderText == prop.Name)
                    {
                        bool show = true;
                        foreach (Attribute attr in prop.GetCustomAttributes(true))
                        {
                            DataGridProperty view = attr as DataGridProperty;
                            show = (view != null && view.State == PropertyState.Viewable);
                        }

                        ToolStripMenuItem menuItem = new ToolStripMenuItem(prop.Name);
                        if (!columnMenu.Items.ContainsKey(menuItem.Text))
                        {
                            menuItem.Name            = prop.Name;
                            menuItem.Click          += new EventHandler(menuItem_Click);
                            menuItem.CheckedChanged += new EventHandler(menuItem_CheckedChanged);
                            columnMenu.Items.Add(menuItem);
                        }
                        if (show)
                        {
                            menuItem.Checked = true;
                            if (!this.columns.Contains(menuItem.Text))
                            {
                                this.columns.Add(prop.Name);
                            }
                        }
                        else
                        {
                            this.Columns[prop.Name].Visible = false;
                        }
                        break;
                    }
                }
                this.columns.Sort();
            }
        }
 set => SetValue(DataGridProperty, value);