Exemplo n.º 1
0
        private void button4_Click(object sender, EventArgs e)
        {
            try
            {
                if (!filter)
                {
                    list   = (ListAtletes)bindingSource1.DataSource;
                    filter = true;
                }
                ListAtletes r2 = new ListAtletes();
                int         a  = 1;
                if (radioButton3.Checked == true)
                {
                    if (RbAge.Checked == true)
                    {
                        r2.atletes = list.atletes.FindAll(x => x.Age > int.Parse(textBox2.Text));
                    }
                    else
                    {
                        r2.atletes = list.atletes.FindAll(x => x.Wins > int.Parse(textBox2.Text));
                    }
                }
                else
                {
                    if (RbWins.Checked == true)
                    {
                        r2.atletes = list.atletes.FindAll(x => x.Wins < int.Parse(textBox2.Text));
                    }
                    else
                    {
                        r2.atletes = list.atletes.FindAll(x => x.Age < int.Parse(textBox2.Text));
                    }
                }

                bindingSource1.DataSource = r2;
                bindingSource1.MoveFirst();
                this.Refresh();
            }
            catch { MessageBox.Show("Ошибка сортировки"); }
        }
Exemplo n.º 2
0
        private void button3_Click(object sender, EventArgs e)

        {
            try
            {
                ListAtletes A = new ListAtletes();
                A = (ListAtletes)bindingSource1.DataSource;
                ListAtletes at = (ListAtletes)bindingSource1.DataSource;

                int a = 1;
                if (radioButton1.Checked == true)
                {
                    a = -1;
                }

                switch (comboBox1.Text)
                {
                case "Имени": at.atletes.Sort((x, y) => a * (x.Name.CompareTo(y.Name))); break;

                case "Фамилии": at.atletes.Sort((x, y) => a * (x.SurName.CompareTo(y.SurName))); break;

                case "Возрату": at.atletes.Sort((x, y) => a * (x.Age.CompareTo(y.Age))); break;

                case "Виду спорта": at.atletes.Sort((x, y) => a * (x.Sport.CompareTo(y.Sport))); break;

                case "Победам": at.atletes.Sort((x, y) => a * (x.Wins.CompareTo(y.Wins))); break;
                }
                bindingSource1.DataSource = at;
                bindingSource1.MoveFirst();
                dataGridView1.DataSource = bindingSource1;
                this.Refresh();
            }
            catch
            {
                MessageBox.Show("Ошибка сортировки");
            }
        }