c# - How to set default display value for data gridview? -
i using data grid view. have list of object lets say.
class abc{ public int i{get;set;} public long b{get;set;} } //in form load list<abc> objlist = new list(); listpopulate(); // populate list. datgridvew.dtasource = objlist;
i want show "-" objabc.i value = 0
, want show "good" objabc.b = 1000
tried cell default format in vain.
can please me out ?
you can use event that, like:
datagridview.cellvaluechanged event
or use datagridview.cellformatting event this:
private void datagridview1_cellformatting(object sender, datagridviewcellformattingeventargs e) { datagridview dgv = (datagridview)sender; if (dgv.columns[e.columnindex].name == "i" && e.rowindex >= 0 && dgv["i", e.rowindex].value int) && (((int)dgv["i", e.rowindex].value) == 0) { e.value = "-"; e.formattingapplied = true; } } else if (dgv.columns[e.columnindex].name == "b" && e.rowindex >= 0 && dgv["b", e.rowindex].value int) && (((int)dgv["b", e.rowindex].value) == 1000) { e.value = "good"; e.formattingapplied = true; } } }
Comments
Post a Comment