G
Guest
I'm newbie on winform and datagrid
I have a DataGrid with a DataGridBoolColumn.
The DataGrid is binded to a DataTable.
The DataTable is the resultset of SQL query "SELECT UserName, Enabled FROM
siteuser" and the Enabled field is a integer type that 1 means enabled while
non-1 means disabled.
I want the DataGridBoolColumn is checked if the Enabled is 1 while keep
unchecked if it's not.
How can I do that? Here is my snippet:
DataGridTableStyle tableStyle = new DataGridTableStyle();
tableStyle.MappingName = "Siteuser";
DataGridTextBoxColumn textColumn = new DataGridTextBoxColumn();
textColumn.MappingName = "UserName";
textColumn.HeaderText = "User Name";
tableStyle.GridColumnStyles.Add(textColumn);
DataGridBoolColumn boolColumn = new DataGridBoolColumn();
boolColumn.MappingName = "Enabled";
boolColumn.HeaderText = "Enabled";
boolColumn.AllowNull = false;
tableStyle.GridColumnStyles.Add(boolColumn);
this.dataGrid1.TableStyles.Add(tableStyle);
this.dataGrid1.DataSource = dataTable;
I have a DataGrid with a DataGridBoolColumn.
The DataGrid is binded to a DataTable.
The DataTable is the resultset of SQL query "SELECT UserName, Enabled FROM
siteuser" and the Enabled field is a integer type that 1 means enabled while
non-1 means disabled.
I want the DataGridBoolColumn is checked if the Enabled is 1 while keep
unchecked if it's not.
How can I do that? Here is my snippet:
DataGridTableStyle tableStyle = new DataGridTableStyle();
tableStyle.MappingName = "Siteuser";
DataGridTextBoxColumn textColumn = new DataGridTextBoxColumn();
textColumn.MappingName = "UserName";
textColumn.HeaderText = "User Name";
tableStyle.GridColumnStyles.Add(textColumn);
DataGridBoolColumn boolColumn = new DataGridBoolColumn();
boolColumn.MappingName = "Enabled";
boolColumn.HeaderText = "Enabled";
boolColumn.AllowNull = false;
tableStyle.GridColumnStyles.Add(boolColumn);
this.dataGrid1.TableStyles.Add(tableStyle);
this.dataGrid1.DataSource = dataTable;