public void LoadData_Course() { dsCourse = new Maticsoft.BLL.Courses().GetList(""); dsCourse.Tables["ds"].Columns["ID"].ColumnName = "课程号"; dsCourse.Tables["ds"].Columns["couName"].ColumnName = "课程名称"; dsCourse.Tables["ds"].Columns["couTime"].ColumnName = "学时"; dsCourse.Tables["ds"].Columns["couPoint"].ColumnName = "学分"; dgvCourse.DataSource = dsCourse.Tables["ds"]; int columnNumber = dgvCourse.ColumnCount; foreach (DataGridViewColumn col in dgvCourse.Columns) { col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; col.SortMode = DataGridViewColumnSortMode.NotSortable; col.FillWeight = 100 / columnNumber; } dgvCourse.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; dgvCourse.AllowUserToAddRows = false; dgvCourse.RowHeadersVisible = false; dgvCourse.ReadOnly = true; }
private void btSearchByCouName_Click(object sender, EventArgs e) { Maticsoft.Common.StaticDataClass.course.ID = ""; string name = tbCouName.Text.Trim(); if (name == null || name == "") { MessageBox.Show("不能有空!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { DataSet ds = new Maticsoft.BLL.Courses().GetList(String.Format(" couName like '%{0}%' ", name)); if (ds.Tables.Count > 0 && ds.Tables["ds"].Rows.Count > 0) { ds.Tables["ds"].Columns["ID"].ColumnName = "课程号"; ds.Tables["ds"].Columns["couName"].ColumnName = "课程名称"; ds.Tables["ds"].Columns["couTime"].ColumnName = "学时"; ds.Tables["ds"].Columns["couPoint"].ColumnName = "学分"; dgvCourse.DataSource = ds.Tables["ds"]; int columnNumber = dgvCourse.ColumnCount; foreach (DataGridViewColumn col in dgvCourse.Columns) { col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; col.SortMode = DataGridViewColumnSortMode.NotSortable; col.FillWeight = 100 / columnNumber; } dgvCourse.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; dgvCourse.AllowUserToAddRows = false; dgvCourse.RowHeadersVisible = false; dgvCourse.ReadOnly = true; } else { MessageBox.Show("查无此课程!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }