How to set the background color of a column in gridview of WPF -
my gridview dynamically generated datatable read sql, want set particular column, say, "salary" have red background color. i've searched many solutions still have no clues.
cmdstring = @" select id, firstname, lastname, title, level, salary emplpyees"; sqlcommand cmd = new sqlcommand(cmdstring, con); sqldataadapter sda = new sqldataadapter(cmd); dt = new datatable("employee"); sda.fill(dt); datagridall.itemssource = dt.defaultview;
you create converter class
public class errorconverters : ivalueconverter { public object convert(object value, type targettype, object parameter, system.globalization.cultureinfo culture) { solidcolorbrush mybrush = default(solidcolorbrush); if ((bool)value == true) { mybrush = new solidcolorbrush(colors.red); } else { mybrush = new solidcolorbrush(colors.black); } return mybrush; } public object convertback(object value, type targettype, object parameter, system.globalization.cultureinfo culture) { //throw new notimplementedexception() return null; } }
then using row template bind color whatever item in database passed converter.
Comments
Post a Comment