Beispiel #1
0
        public static void AddTableControls(FormMain parent, ToolStripMenuItem menu, ExtendedDataGridView dataGridView, BindingSource bindingSource)
        {
            menu.DropDownItems.Add(Decorator.CreateCheckboxToolStrip(true, "Header", isVisible => dataGridView.HeaderVisible        = isVisible));
            menu.DropDownItems.Add(Decorator.CreateCheckboxToolStrip(true, "Footer", isVisible => dataGridView.FooterVisible        = isVisible));
            menu.DropDownItems.Add(Decorator.CreateCheckboxToolStrip(false, "Selector", isVisible => dataGridView.RowHeadersVisible = isVisible));
            menu.DropDownItems.Add(Decorator.CreateCheckboxToolStrip(true, "Multiline", isEnabled => dataGridView.Multiline         = isEnabled));

            menu.DropDownItems.Add(Decorator.CreateButtonToolStrip("Data Format", (sender, args) =>
            {
                DataGridView grid       = new DataGridView();
                grid.Dock               = DockStyle.Fill;
                grid.AllowUserToAddRows = false;
                grid.RowHeadersVisible  = false;
                grid.RowTemplate.DefaultCellStyle.Padding = new Padding(3, 5, 3, 5);
                grid.ColumnHeadersHeight += 10;
                grid.RowTemplate.Height  += 10;

                grid.Columns.Add(new DataGridViewColumn {
                    Name = "№", CellTemplate = new DataGridViewTextBoxCell(), Width = 80, ReadOnly = true
                });
                grid.Columns.Add(new DataGridViewColumn {
                    Name = "Type", CellTemplate = new DataGridViewTextBoxCell(), Width = 150, ReadOnly = true
                });
                grid.Columns.Add(new DataGridViewColumn
                {
                    Name             = "Format (Editable)",
                    CellTemplate     = new DataGridViewTextBoxCell(),
                    Width            = 300,
                    DefaultCellStyle = new DataGridViewCellStyle
                    {
                        NullValue = "[NULL]"
                    }
                });

                int index = 0;
                foreach (var column in parent.Columns)
                {
                    grid.Rows.Add(++index, column.type.Name, column.Format);
                }

                grid.CellValueChanged += (o, ev) => parent.Columns[ev.RowIndex].Format = grid.Rows[ev.RowIndex].Cells[ev.ColumnIndex].Value.ToString();

                Form dialog          = new Form();
                dialog.Text          = "Data rows format";
                dialog.Size          = new Size(400, 200);
                dialog.MinimizeBox   = false;
                dialog.MaximizeBox   = false;
                dialog.StartPosition = FormStartPosition.CenterParent;
                dialog.AutoScaleMode = AutoScaleMode.Font;
                dialog.Font          = parent.Font;

                dialog.Controls.Add(grid);
                dialog.Show(parent);
            }));

            menu.DropDownItems.Add(Decorator.CreateButtonToolStrip("Config Folder", (sender, args) =>
            {
                var fullFilePath = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath;
                Process.Start("explorer.exe", Path.GetDirectoryName(fullFilePath));
            }));
        }