vb.net - change data grid view row colour depend upon the value -
i have datagridview this:
i binding datagridview this:
dim cmd new sqlcommand("dashbordfetch", con.connect) cmd.commandtype = commandtype.storedprocedure cmd.parameters.add("@locid", sqldbtype.int).value = locid da.selectcommand = cmd da.fill(ds) dgvdashboard.datasource = ds.tables(0)
i want datagridview have red row color when value 1. how can that? working in vb.net.
i have tried code in 1 of answers provided, looks this:
try
private sub dgvdashboard_cellformatting(byval sender object, byval e system.windows.forms.datagridviewcellformattingeventargs) handles dgvdashboard.cellformatting dim drv datarowview if e.rowindex >= 0 ' add condition here ignore following if e.rowindex <= ds.tables(0).rows.count - 1 drv = ds.tables(0).defaultview.item(e.rowindex) dim c color if drv.item("value").tostring = "1" c = color.red end if e.cellstyle.backcolor = c end if end if end sub
let me know if doesn't work.
Comments
Post a Comment