Click here to Skip to main content
15,886,963 members
Home / Discussions / C#
   

C#

 
GeneralRe: I need help improving my code Pin
V.5-Nov-15 19:36
professionalV.5-Nov-15 19:36 
GeneralRe: I need help improving my code Pin
John Torjo5-Nov-15 19:45
professionalJohn Torjo5-Nov-15 19:45 
GeneralRe: I need help improving my code Pin
V.5-Nov-15 19:58
professionalV.5-Nov-15 19:58 
GeneralRe: I need help improving my code Pin
John Torjo5-Nov-15 20:04
professionalJohn Torjo5-Nov-15 20:04 
AnswerRe: I need help improving my code Pin
BillWoodruff5-Nov-15 19:25
professionalBillWoodruff5-Nov-15 19:25 
GeneralRe: I need help improving my code Pin
Gilbert Consellado5-Nov-15 23:42
professionalGilbert Consellado5-Nov-15 23:42 
GeneralRe: I need help improving my code Pin
BillWoodruff6-Nov-15 0:42
professionalBillWoodruff6-Nov-15 0:42 
GeneralRe: I need help improving my code Pin
Gilbert Consellado6-Nov-15 2:17
professionalGilbert Consellado6-Nov-15 2:17 
Yes it was a from Devexpres, actually i was implementing the ValidationRule from DevExpress.XtraEditors.DXErrorProvider then use it with dxValidationProvider

here the code that will validate an int

C#
public sealed class ValidateInteger : ValidationRule
{
    private int _maxValue = int.MaxValue;
    private int _minValue = int.MinValue;
    private bool _IsAllowNull;

    public ValidateInteger(bool isAllowNull = false)
    {
        _IsAllowNull = isAllowNull;
    }

    public ValidateInteger(int min, int max, bool isAllowNull = false)
    {
        _maxValue = max;
        _minValue = min;
        _IsAllowNull = isAllowNull;
    }

    public override bool Validate(Control control, object value)
    {
        if (value == null && !_IsAllowNull)
        {
            ErrorText = "Please provided valid number without a decimal point.";
            return false;
        }

        if (value.ToString().Contains("."))
        {
            ErrorText = "Decimal value is not allowed";
            return false;
        }

        if (!value.IsNumber())
        {
            ErrorText = "Please provided valid number without a decimal point.";
            return false;
        }
        if (value.ToInt() < _minValue || value.ToInt() > _maxValue)
        {
            ErrorText = "Value should not be greater than " + _maxValue + " or less than " + _minValue;
            return false;
        }
        return true;
    }
}


then use it like this

dxValidationProviderMain.SetValidationRule(txt_height, new Validators.ValidateInteger(false));


then call
dxValidationProviderMain.Validate()

GeneralRe: I need help improving my code Pin
BillWoodruff6-Nov-15 2:40
professionalBillWoodruff6-Nov-15 2:40 
GeneralRe: I need help improving my code Pin
Gilbert Consellado6-Nov-15 3:00
professionalGilbert Consellado6-Nov-15 3:00 
GeneralRe: I need help improving my code Pin
BillWoodruff6-Nov-15 4:14
professionalBillWoodruff6-Nov-15 4:14 
GeneralRe: I need help improving my code Pin
Gilbert Consellado6-Nov-15 4:45
professionalGilbert Consellado6-Nov-15 4:45 
AnswerRe: I need help improving my code Pin
V.5-Nov-15 19:52
professionalV.5-Nov-15 19:52 
GeneralRe: I need help improving my code Pin
Gilbert Consellado6-Nov-15 0:04
professionalGilbert Consellado6-Nov-15 0:04 
AnswerRe: I need help improving my code Pin
Chris Quinn5-Nov-15 22:14
Chris Quinn5-Nov-15 22:14 
GeneralRe: I need help improving my code Pin
Gilbert Consellado6-Nov-15 0:08
professionalGilbert Consellado6-Nov-15 0:08 
AnswerRe: I need help improving my code Pin
Rob Philpott5-Nov-15 23:03
Rob Philpott5-Nov-15 23:03 
GeneralRe: I need help improving my code Pin
Gilbert Consellado6-Nov-15 0:12
professionalGilbert Consellado6-Nov-15 0:12 
Questionwhy you cannot "spoof" an Interface to use to cast an Object to a Type you know the structure of ? Pin
BillWoodruff4-Nov-15 23:25
professionalBillWoodruff4-Nov-15 23:25 
AnswerRe: why you cannot "spoof" an Interface to use to cast an Object to a Type you know the structure of ? Pin
Eddy Vluggen4-Nov-15 23:42
professionalEddy Vluggen4-Nov-15 23:42 
GeneralRe: why you cannot "spoof" an Interface to use to cast an Object to a Type you know the structure of ? Pin
BillWoodruff5-Nov-15 4:44
professionalBillWoodruff5-Nov-15 4:44 
GeneralRe: why you cannot "spoof" an Interface to use to cast an Object to a Type you know the structure of ? Pin
Eddy Vluggen5-Nov-15 8:28
professionalEddy Vluggen5-Nov-15 8:28 
AnswerRe: why you cannot "spoof" an Interface to use to cast an Object to a Type you know the structure of ? PinPopular
Pete O'Hanlon5-Nov-15 0:55
mvePete O'Hanlon5-Nov-15 0:55 
GeneralRe: why you cannot "spoof" an Interface to use to cast an Object to a Type you know the structure of ? Pin
BillWoodruff5-Nov-15 4:46
professionalBillWoodruff5-Nov-15 4:46 
GeneralRe: why you cannot "spoof" an Interface to use to cast an Object to a Type you know the structure of ? Pin
Pete O'Hanlon5-Nov-15 5:07
mvePete O'Hanlon5-Nov-15 5:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.