日期:2014-05-18  浏览次数:20646 次

大家好!想问一个关于dataGridView控件的问题~~
我在数据库中数据是“1”或“0”,如何在dataGridView控件中当值为“1”时当打扣,为“0”值时则留空?


------解决方案--------------------
checkbox1.Checked=(查到的数据==0?true:false);
------解决方案--------------------
C# code

        private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == "0")
            {
                e.Value = "";
            }
            else
            {
                e.Value = "√";
            }
        }

------解决方案--------------------
查出数据时先判断下
bool value=(数据==0?true:false)
然后if(value){。。。。。。}
else{。。。。。}