读书人

winform中DataGridView绑定数据。该如

发布时间: 2013-02-17 10:44:46 作者: rapoo

winform中DataGridView绑定数据。
在winform中将数据绑定到DataGridView时,我数据库里面存的是bool类型的字段IsExist,我要再DataGridView中显示“是,否” ,该怎么做啊?
我的数据源是List<Model>类型的,因为IsExist是bool类型的我也无法在后台将IsExist的值变成“是,否”

[解决办法]
在cellformating事件中处理


private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.RowIndex < 0) return;
if (e.Value.ToString() == "1")
e.Value = "是";
else
e.Value = "否";

}

[解决办法]
你改一下sql文。增加个字段。这样绑定的时候就可以显示你想要的结果了。
[解决办法]
这个直接在sql语句里转换就行了
case when col1=1 then '是' else '否' end
[解决办法]
case IsExist when '1' then '是' else '否'
[解决办法]
IList<Model> list = new List<Model>();
foreach (Model me in list)
{
try
{
me.IsExist=(me.IsExist == true? "是" :"否")
....
list.Add(me);
}
catch
{
throw;
}
}
return list;
[解决办法]
引用:
这个直接在sql语句里转换就行了
case when col1=1 then '是' else '否' end


这种最直接.

还可以添加事件转换.
[解决办法]
好多要改,直接写个存储过程得了,自己去拼凑sql

读书人网 >C#

热点推荐