日期:2014-05-17  浏览次数:20706 次

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