M
michael sorens
If I populate a DataGridView with a query supplied at runtime, boolean fields
render as a CheckBox instead of just a text rendering of '0' or '1'. That is
nice sometimes, but I would like the flexibility of showing text sometimes as
well. Is there an easy way to get the text '0' or '1' instead of the
CheckBox? My DataGridView is filled in with this basic code:
DataTable dataTable = new DataTable();
qBindingSource.DataSource = dataTable;
qBindingSource.DataMember = null;
SqlDataAdapter tableAdapter = new SqlDataAdapter(myQuery, myConnString);
tableAdapter.Fill(dataTable);
Note that the query is completely arbirtrary so I do not know in advance
which columns, if any, are boolean.
My basic approach would be to have a button that lets the user switch
between "raw" (i.e. 0 or 1 showing) and "enhanced" (i.e. with checkboxes)
displays. Then after I load the DataGridView, scan each column type, looking
for DataGridViewCheckBoxColumn. Could I just change that to
DataGridViewTextBoxColumn on the fly? Also, when I am showing checkboxes, I
want to distinguish 0 from null, so could I change the ThreeState property on
the fly as well?
Environment: C# 2.0, .NET 2.0, VS2005
render as a CheckBox instead of just a text rendering of '0' or '1'. That is
nice sometimes, but I would like the flexibility of showing text sometimes as
well. Is there an easy way to get the text '0' or '1' instead of the
CheckBox? My DataGridView is filled in with this basic code:
DataTable dataTable = new DataTable();
qBindingSource.DataSource = dataTable;
qBindingSource.DataMember = null;
SqlDataAdapter tableAdapter = new SqlDataAdapter(myQuery, myConnString);
tableAdapter.Fill(dataTable);
Note that the query is completely arbirtrary so I do not know in advance
which columns, if any, are boolean.
My basic approach would be to have a button that lets the user switch
between "raw" (i.e. 0 or 1 showing) and "enhanced" (i.e. with checkboxes)
displays. Then after I load the DataGridView, scan each column type, looking
for DataGridViewCheckBoxColumn. Could I just change that to
DataGridViewTextBoxColumn on the fly? Also, when I am showing checkboxes, I
want to distinguish 0 from null, so could I change the ThreeState property on
the fly as well?
Environment: C# 2.0, .NET 2.0, VS2005