因此,我正在使用以下方法在datagridview中显示数据:
con.Open();
adap = new SqlDataAdapter("SELECT ID, Course_Description as
'Course',Student_Name as 'Name', Classroom as 'Room', Seat_Number as
'Seat No.' from TBL_SeatPlan WHERE Course_Description = '"+
cmbCourse.Text +"' ", con);
ds = new System.Data.DataSet();
adap.Fill(ds,"SeatPlan");
dtSeat.DataSource = ds.Tables[0];
DataGridViewComboBoxColumn Dcolumn = new DataGridViewComboBoxColumn();
Dcolumn.HeaderText = "Status";
Dcolumn.Items.Add("Absent");
Dcolumn.Items.Add("Present");
con.Close();
我想做的是添加另一列带有组合框的框,以验证学生是否缺席。
DataGridViewComboBoxColumn Dcolumn = new DataGridViewComboBoxColumn();
Dcolumn.HeaderText = "Status";
Dcolumn.Items.Add("Absent");
Dcolumn.Items.Add("Present");
这行代码似乎没有出现在我的datagridview中
答案 0 :(得分:0)
是的,我现在可以设法添加另一列,但是我想要的是在我添加的那列中放一个组合框。
con.Open();
adap = new SqlDataAdapter("SELECT ID, Course_Description as 'Course', Year_Level as
'Year Level', Student_Name as 'Name', Classroom as 'Room', Seat_Number as 'Seat No.'
from TBL_SeatPlan WHERE Course_Description = '" + cmbCourse.Text + "' and Year_Level
= '" + cmbYrLvl.Text + "' ", con);
DataTable dt = new DataTable();
adap.Fill(dt);
dtSeat.DataSource = dt;
DataGridViewComboBoxColumn Dcolumn = new DataGridViewComboBoxColumn();
dt.Columns.Add(new DataColumn("Status", typeof(char)));
Dcolumn.HeaderText = "Status";
Dcolumn.Items.Add("Absent");
Dcolumn.Items.Add("Present");
con.Close();