Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set valuetype as positive int?

Question should be self explanatory. I have a datagridview which has a column whose cells should accept only positive integer upon user input.

So how can I set something like this:

            dgv.Columns[i].ValueType = typeof(int > 0);

??

Of course I can handle a separate validation at cellValueChanged event. But since I have all validation handled in DataError event automatically (since I set valueType for each column), I would like my above validation to be handled here

    private void dgv_DataError(object sender, DataGridViewDataErrorEventArgs e)
    {
        // not fair..
        e.Cancel = true;
    }

How to?

Update: Since I hear a lot of negatives about uint (as proposed by one of the answers) like uints are not CLS compliant, not all language supports it etc, is it ok to use just for validation purpose like above?

like image 868
nawfal Avatar asked Dec 27 '22 08:12

nawfal


2 Answers

Declare uint type variable

minimum of uint is 0

maximun od uint is 4294967295

like image 147
Manas Avatar answered Dec 30 '22 10:12

Manas


The upper part of the question should be easily solved like this:

dgv.Columns[i].ValueType = typeof(uint);

The lower part I don't understand at all.

like image 26
Nuffin Avatar answered Dec 30 '22 09:12

Nuffin