Doubt with validations [ I Need your help !!]

oze_lokoze_lok ESMember

Hello guys! I have a little doubt with my cross platform program.

I start to a validate fields and I find a problem that prevent my progress. I want that my App show a Display Alert when you leave a field empty.

With strings no problems but with integers I find my problem. If in my application leave the picker field empty(without select), never show me the message and always saved correctly. Instead with the string Id empty yes that show the message..... This is my code:

**//Event in button
void btnSave_Clicked(object sender, EventArgs a)
{
string id = txtid.Text;

       //int number = pckNumber.SelectedIndex;

       //User iduser = lsvUsers.SelectedItem as User;

                              //Get the picker value
        if (String.IsNullOrEmpty(id) || String.IsNullOrEmpty(pckNumber.SelectedIndex.ToString()  || String.IsNullOrEmpty(lsvUsers.SelectedItem.ToString()) ) 
        {
            DisplayAlert("Error", "Incorrect Field", "Back");
        }
        else
        {

       int number = pckNumber.SelectedIndex;
           User iduser = lsvUsers.SelectedItem as User;

            if (ID == String.Empty)
            {   //Save in database
                App.AzureService.Save(id, number, iduser.Id);
                DisplayAlert("Warning", "You saved!!", "Back");
            }
            else  //Modify in database
                App.AzureService.Modify(id, number, iduser.Id);

            Navigation.PopAsync();
        }
    }

**

Help me please!! And sorry for my English!!

Best Answers

Answers

  • oze_lokoze_lok ESMember

    @pedrohex said:
    Well .. String.IsNullOrEmpty(pckNumber.SelectedIndex.ToString() is "-1"
    I suggest you change your validation to Int also

    if (pckNumber.SelectedIndex < 0)

    cheers!

    Great! Now run !! :smiley: But would like that "lsvUsers.SelectedItem" also run... Can you help me?? Thanks...

  • oze_lokoze_lok ESMember

    @pedrohex said:
    SelectedItem suggests an object associated with it.
    You may try

    lsvUsers.SelectedItem != null

    Great!! My project now run with the next correction:

    if( lsvUsers.SelectedItem == null)
    //code

    Thanks!!

Sign In or Register to comment.