DevExpress CheckEdit / RepositoryItemCheckEdit does not read database value

It can be a nuissance sometimes, to get DevExpress‘ CheckEdit or RepositoryItemCheckEdit to display what’s in the database record. I searched for quite a while and then found out it was the number format of the field, that prevented it to display the desired on/odff status:

public RepositoryItemCheckEdit GetRepositoryEditorCheck()
    var rep = new RepositoryItemCheckEdit();
    rep.AllowGrayed = false;
    rep.CheckStyle = CheckStyles.Standard;
    rep.NullStyle = StyleIndeterminate.Unchecked;
    rep.ValueChecked = Convert.ChangeType(1, typeof(sbyte));        // IMPORTANT: use the right type !!!
    rep.ValueUnchecked = Convert.ChangeType(0, typeof(sbyte));
    return rep;

This only gets clear after your know the solution: a 1 is not a 1. It might be 1 of type Int16, Int32, SByte or other number format. In the database this is a „tinyint“ (MySQL). So have a look at your Entity Framework or Dataset field or POCO definition to check back on this – and use the correct format of your 1s and 0s.

My Grid only started to display the on/off status according to the datbase’s 1s and 0s after I converted the literals to go into the ValueChecked resp. ValueUnchecked assignments to Sbyte… A problem you might not spot a first sight, although it’s quite clear once you solved it.

Kommentar verfassen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert