KazooSoft
asked on
Programmatically create Check box DataGridView with INT fields
Hey all!
Just a small problem at the moment which I need solving if anyone can help.
I would like to programmatically make all int fields within a DataGridView check boxes. Does anyone know how? I use the following to fill the DataGrid
But they just show up as blank fields with either a 1 or null.
Cheers,
Just a small problem at the moment which I need solving if anyone can help.
I would like to programmatically make all int fields within a DataGridView check boxes. Does anyone know how? I use the following to fill the DataGrid
DataTable DT_Courses = new DataTable();
DT_Courses = KazooSoft.MSSQL_Functions.DBQuery(
"SELECT students.student_cn, students.student_fn, students.student_ln, course.course_title, lm_statements.archived, lm_statements.printed " +
"FROM course INNER JOIN " +
"lm_statements ON course.course_code = lm_statements.course_id INNER JOIN " +
"students ON lm_statements.student_id = students.person_code " +
"WHERE course.course_code = '"+ combo_Courses.SelectedValue.ToString() +"'",
KazooReports.Properties.Settings.Default.MSSQL_username,
KazooReports.Properties.Settings.Default.MSSQL_password,
KazooReports.Properties.Settings.Default.MSSQL_database,
KazooReports.Properties.Settings.Default.MSSQL_server
);
dataGridView_PrintArchive.DataSource = DT_Courses;
But they just show up as blank fields with either a 1 or null.
Cheers,
If you set the DGV to Autogenerate columns, it's going to output all of them as text strings. The easiest thing to do here would be to bind the DGV to the datasource in the VS Designer and then change the column types there.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
when you select, select as boolean
ie
"SELECT cast(case when students.student_cn == 0 then 0 else 1 end as bit) as students.student_cn, students.student_fn, students.student_ln, course.course_title,
...
ie
"SELECT cast(case when students.student_cn == 0 then 0 else 1 end as bit) as students.student_cn, students.student_fn, students.student_ln, course.course_title,
...
ASKER
EDDYKT: That causes a SQL error
Nash2334: I know this is a solution but not my ideal solution.
"SELECT students.student_cn, students.student_fn, students.student_ln, course.course_title, lm_statements.archived, cast(case when lm_statements.printed == 0 then 0 else 1 end as bit) as lm_statements.printed " +
"FROM course INNER JOIN " +
"lm_statements ON course.course_code = lm_statements.course_id INNER JOIN " +
"students ON lm_statements.student_id = students.person_code " +
"WHERE course.course_code = '"+ combo_Courses.SelectedValue.ToString() +"'",
Nash2334: I know this is a solution but not my ideal solution.
should be just single =
ie
cast(case when lm_statements.printed = 0 then 0 else 1 end as bit) as lm_statements.printed
ie
cast(case when lm_statements.printed = 0 then 0 else 1 end as bit) as lm_statements.printed
ASKER
That kind of works but. The values in the database are either null, 0, 1. How will I get it to check for example if printer = 0 or null else 1 end?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you so much.
If i use
cast(case when lm_statements.printed is null or lm_statements.printed = 0 then 0 else 1 end as bit) as printed
Then it also seems to make the Archive field a bool too!? Strange but great thank you!
If i use
cast(case when lm_statements.printed is null or lm_statements.printed = 0 then 0 else 1 end as bit) as printed
Then it also seems to make the Archive field a bool too!? Strange but great thank you!