public ChangeGroupForm(BookList list) { InitializeComponent(); label1.Text = ""; this.Text = "Выбор группы"; this.list = list; using (StreamReader sr = new StreamReader("Groups.txt")) { List <string> groups = new List <string>(); while (!sr.EndOfStream) { string s = sr.ReadLine(); if (!String.IsNullOrWhiteSpace(s)) { groups.Add(s); } } listBox1.Items.AddRange(groups.ToArray()); } listBox1.SetSelected(listBox1.Items.IndexOf(list.Group), true); }
// Главная форма с таблицей public MainForm() { books = new BookList("Main Group"); books.Read(); InitializeComponent(); dataGridView1.DataSource = books.Books; dataGridView1.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect; label1.Text = ""; // Главный ряд кнопок в меню ToolStripMenuItem fileItem = new ToolStripMenuItem("Файл"); ToolStripMenuItem editItem = new ToolStripMenuItem("Правка"); ToolStripMenuItem tableOrderItem = new ToolStripMenuItem("Порядок"); // Кнопки в подменю файл ToolStripMenuItem fileGroupItem = new ToolStripMenuItem("Группа"); ToolStripMenuItem fileSaveItem = new ToolStripMenuItem("Сохранить"); fileGroupItem.Click += ChangeGroupItemClisk; fileSaveItem.Click += SaveItemClick; fileItem.DropDownItems.Add(fileGroupItem); fileItem.DropDownItems.Add(fileSaveItem); // Кнопки в подменю порядок ToolStripMenuItem tableOrderNameItem = new ToolStripMenuItem("По названию"); ToolStripMenuItem tableOrderAuthorItem = new ToolStripMenuItem("По имени автора"); ToolStripMenuItem tableOrderPublisherItem = new ToolStripMenuItem("По издателю"); ToolStripMenuItem tableOrderGenreItem = new ToolStripMenuItem("По жанру"); ToolStripMenuItem tableOrderPriceItem = new ToolStripMenuItem("По цене"); // Упорядочивание tableOrderNameItem.Click += delegate { label1.Text = ""; books.Books = books.Books.OrderBy(x => x.Name).ToList(); dataGridView1.DataSource = new Book(); dataGridView1.DataSource = books.Books; }; tableOrderAuthorItem.Click += delegate { label1.Text = ""; books.Books = books.Books.OrderBy(x => x.Author).ToList(); dataGridView1.DataSource = new Book(); dataGridView1.DataSource = books.Books; }; tableOrderPublisherItem.Click += delegate { label1.Text = ""; books.Books = books.Books.OrderBy(x => x.Publicher).ToList(); dataGridView1.DataSource = new Book(); dataGridView1.DataSource = books.Books; }; tableOrderPriceItem.Click += delegate { label1.Text = ""; books.Books = books.Books.OrderBy(x => x.Price).ToList(); dataGridView1.DataSource = new Book(); dataGridView1.DataSource = books.Books; }; tableOrderGenreItem.Click += delegate { label1.Text = ""; books.Books = books.Books.OrderBy(x => x.Genre).ToList(); dataGridView1.DataSource = new Book(); dataGridView1.DataSource = books.Books; }; tableOrderItem.DropDownItems.Add(tableOrderNameItem); tableOrderItem.DropDownItems.Add(tableOrderAuthorItem); tableOrderItem.DropDownItems.Add(tableOrderPublisherItem); tableOrderItem.DropDownItems.Add(tableOrderGenreItem); tableOrderItem.DropDownItems.Add(tableOrderPriceItem); // Кнопки в подменю правка ToolStripMenuItem editAddItem = new ToolStripMenuItem("Добавить"); ToolStripMenuItem editUpdateItem = new ToolStripMenuItem("Изменить"); ToolStripMenuItem editDeleteItem = new ToolStripMenuItem("Удалить"); editAddItem.Click += button1_Click; editUpdateItem.Click += button2_Click; editDeleteItem.Click += button3_Click; editItem.DropDownItems.Add(editAddItem); editItem.DropDownItems.Add(editUpdateItem); editItem.DropDownItems.Add(editDeleteItem); // Добавление элементов в меню menuStrip1.Items.Add(fileItem); menuStrip1.Items.Add(editItem); menuStrip1.Items.Add(tableOrderItem); // Кнопки в контекстном меню ToolStripMenuItem contextEditAddItem = new ToolStripMenuItem("Добавить"); ToolStripMenuItem contextEditUpdateItem = new ToolStripMenuItem("Изменить"); ToolStripMenuItem contextEditDeleteItem = new ToolStripMenuItem("Удалить"); contextEditAddItem.Click += button1_Click; contextEditUpdateItem.Click += button2_Click; contextEditDeleteItem.Click += button3_Click; // Добавление элементов в контекстное меню contextMenuStrip1.Items.Add(contextEditAddItem); contextMenuStrip1.Items.Add(contextEditUpdateItem); contextMenuStrip1.Items.Add(contextEditDeleteItem); dataGridView1.ContextMenuStrip = contextMenuStrip1; dataGridView1.CellMouseDown += dataGridView1_CellMouseDown; }