When binding a DataTable to a DataGridView , if the DataTable has a
non-nullable bit column ( 0 , 1 ) , is it possible to have 0 displayed as
"false" and 1 as "true" ?
NOTE: I need to keep the
DataGridView.DataSource = DataTable
DataGridView.Refresh()
syntax ...
Marc Gravell - 01 Jul 2008 08:10 GMT
Have you actually typed the column as bool/Boolean? It seems to work
fine for me (unless you are fussy about the casing). Example below. If
the DataTable is "typed" (i.e. SomeDataTable, SomeDataRow etc) rather
than a vanilla DataTable, you can do a lot by monkeying with the
TypeConverter on a per-property basis (I can elaborate if that would be
useful).
Marc
DataTable dt = new DataTable();
dt.Columns.Add("Foo", typeof(bool));
dt.Rows.Add(false);
dt.Rows.Add(true);
Application.EnableVisualStyles();
Application.Run(
new Form {
Controls = {
new DataGridView {
Columns = {
new DataGridViewTextBoxColumn {
DataPropertyName = "Foo"
}
},
Dock = DockStyle.Fill,
DataSource = dt
}
}
});