请问,iobject .net中按虚模式填充datagridview,列类型为boolean时,按DataGridViewComboBoxColumn类型建的,
else if (mField.Type == FieldType.Boolean)
{
DataGridViewComboBoxColumn col = new DataGridViewComboBoxColumn();
col.Name = mField.Name;
col.HeaderText = columnTitle;
//List<Boolean> T_Fields = new List<Boolean>();
//T_Fields.Add(true);
//T_Fields.Add(false);
////col.Items = T_Fields;
//col.DataSource = T_Fields;
col.Items.AddRange(true , false);
col.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
//根据是否系统字段设置颜色;
if (mField.IsSystemField)
{
col.ReadOnly = true;
col.DefaultCellStyle.BackColor = Color.FromArgb(240, 240, 240);
col.Width = 100;
}
else
{
col.DefaultCellStyle.BackColor = Color.FromArgb(255, 255, 255);
}
dataGridView1.Columns.Add(col);
}
按虚模式填充单元格
//单元格填充事件;
private void dataGridView1_CellValueNeeded(object sender, DataGridViewCellValueEventArgs e)
{
if (e.RowIndex == this.dataGridView1.RowCount)
return;
//读取数据;
string colName = this.dataGridView1.Columns[e.ColumnIndex].Name;
recordset_property.MoveTo(e.RowIndex);
if (recordset_property.GetFieldInfos()[colName].Type == FieldType.Boolean)
{
if (Convert.ToBoolean(recordset_property.GetFieldValue(colName)))
{
e.Value = Convert.ToBoolean(recordset_property.GetFieldValue(colName));
}
} else{
e.Value = recordset_property.GetFieldValue(colName);
}
// dataGridView1.Update();
}
为什么这样所有的值都显示False,实际不是都是Fasle?谢谢!