0

So i am displaying my data in my datagridview using this:

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();

what i want to do is add another column that has a combo box to verify if a student is absent or present.

DataGridViewComboBoxColumn Dcolumn = new DataGridViewComboBoxColumn();
Dcolumn.HeaderText = "Status";
Dcolumn.Items.Add("Absent");
Dcolumn.Items.Add("Present");

this line of codes does not seem to appear in my datagridview

  • Take a look at this answer: https://stackoverflow.com/a/5524129/9365244 – JayV Jan 23 '19 at 08:37
  • Possible duplicate of [Programmatically add new column to DataGridView](https://stackoverflow.com/questions/5524075/programmatically-add-new-column-to-datagridview) – Markus Deibel Jan 23 '19 at 08:50
  • __Do not__ call a `DataGridView`a `GridView` or a `DataGrid` and vice versa!! This is wrong and confusing as those are different controls. Always call things by their __right__ name! - Putting two (or any nuumber of real controls) into a DGV cell indeed is complicated. Why not have two columns? – TaW Jan 23 '19 at 18:49
  • mine is not bound to a datatable it seems ? – Diether Noche Jan 25 '19 at 10:40

1 Answers1

0

Yes i can now manage to add another column but what exactly i want is put a combo Box in that column i added.

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();