Пример #1
0
        private void txtFind_TextChanged(object sender, EventArgs e)
        {
            // filter datagrid
            try
            {
                gridLecturers.DataSource = null;
                gridLecturers.DataSource = LecturerDataAccess.filterLecturers(txtFind.Text)
                                           .Select(x => new
                {
                    LecturerID = x.LecturerId,
                    Surname    = x.SurName,
                    Firstname  = x.FirstName,
                    Lastname   = x.LastName,
                    Nic        = x.Nic,
                    Mobile     = x.Mobile,
                    Email      = x.Email,
                    Address    = x.Address,
                    isRemoved  = x.IsRemoved
                }).ToList();

                gridLecturers.Columns["LecturerID"].HeaderText = "Lecturer ID";
                gridLecturers.Columns["Surname"].HeaderText    = "Surname";
                gridLecturers.Columns["Firstname"].HeaderText  = "First Name";
                gridLecturers.Columns["Lastname"].HeaderText   = "Last Name";
                gridLecturers.Columns["Nic"].HeaderText        = "NIC #";
                gridLecturers.Columns["Mobile"].HeaderText     = "Mobile #";
                gridLecturers.Columns["Email"].HeaderText      = "E-mail";
                gridLecturers.Columns["Address"].HeaderText    = "Address";
                gridLecturers.Columns["isRemoved"].HeaderText  = "Inactive";;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed : " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #2
0
        public void findLecturers()
        {
            // filter lecturers based on search keyword
            try
            {
                var searchValue = txtFindLecturer.Text;
                var source      = LecturerDataAccess.filterLecturers(searchValue);
                gridLecturer.DataSource = source
                                          .Select(x => new
                {
                    LecturerId = x.LecturerId,
                    Surname    = x.SurName,
                    Firstname  = x.FirstName,
                    Lastname   = x.LastName,
                    Nic        = x.Nic,
                    Email      = x.Email,
                    Mobile     = x.Mobile,
                    Address    = x.Address,
                    IsRemoved  = x.IsRemoved
                }).Where(x => x.IsRemoved == false).ToList();

                gridLecturer.Columns["LecturerId"].HeaderText = "Lecturer ID";
                gridLecturer.Columns["Surname"].HeaderText    = "Surname";
                gridLecturer.Columns["Firstname"].HeaderText  = "Firstname";
                gridLecturer.Columns["Lastname"].HeaderText   = "Lastname";
                gridLecturer.Columns["Nic"].HeaderText        = "NIC #";
                gridLecturer.Columns["Email"].HeaderText      = "E-mail";
                gridLecturer.Columns["Mobile"].HeaderText     = "Mobile";
                gridLecturer.Columns["Address"].HeaderText    = "Address";
                gridLecturer.Columns["IsRemoved"].HeaderText  = "Status";

                gridLecturer.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                gridLecturer.Columns[4].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                gridLecturer.Columns[5].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                gridLecturer.Columns[6].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                gridLecturer.Columns[8].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed : " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }