Καλώς ορίσατε στο dotNETZone.gr - Σύνδεση | Εγγραφή | Βοήθεια
σε

 

Αρχική σελίδα Ιστολόγια Συζητήσεις Εκθέσεις Φωτογραφιών Αρχειοθήκες

Πως πιανεις το Exception thrown από ένα property που αλλαζει μέσο DataBinding

Îåêßíçóå áðü ôï ìÝëïò Nassos.NET. Τελευταία δημοσίευση από το μέλος Nassos.NET στις 17-11-2006, 15:09. Υπάρχουν 4 απαντήσεις.
Ταξινόμηση Δημοσιεύσεων: Προηγούμενο Επόμενο
  •  17-11-2006, 12:19 20608

    Πως πιανεις το Exception thrown από ένα property που αλλαζει μέσο DataBinding

    Οκ έχω κάτι δύσκολο, ελπίζω να το ξέρει κάποιος.

    Έχω ενα Property σε ενα Class που κάτω απο ορισμένες συνθίκες throws ένα Exception ο Κώδικας του Property :



    public bool IsAdministrator
    {
       get { return Convert.ToBoolean(_Record.WL_ISADMIN.Value); }
       set
       {
          //If the New value is true
          if (value)
          {
             if (CanBeTheUserAdmin())//Check if the Garage Has Admin User
             {
                //No Admin User, This Becomes Admin
                _Record.WL_ISADMIN.Value = value;
             }
             else//If the Garage Has Admin User throw Exception
                throw new Exception("Δεν Μπορείτε να κάνετε τον Χρήστη Administrator διότι Υπαρχει ήδη Administrator για το Συνεργείο!!");
       }else//If the New value is False, applying it to the user
          _Record.WL_ISADMIN.Value = value;
    }
    }

    Στην Οθόνη μου κάνω Bind ενός CheckBox με το Property του Class μου ο κώδικας:

    Binding adminBind = new Binding("Checked", user, "IsAdministrator");
    this.chkIsAdmin.DataBindings.Add(adminBind);

    Όταν το Property throws το Exception το control δεν φευγει απο Focused και λοκαρι την οθόνη χωρίς μήνυμα!!

    Προσπάθησα να πίασω το DataError Event του BindManager κώδικας :



    BindingManagerBase adminManager = this.BindingContext[user, "IsAdministrator"];

    adminManager.DataError += new BindingManagerDataErrorEventHandler(adminManager_DataError);

    Αλλα τίποτα

    Έχει καποιος καμία ιδέα για το πώς θα πιασω το Exception???

    thnx in Advance

    Nassos


    "Success is the ability to go from one failure to another with no loss of enthusiasm."
    Winston Churchill

    "Quality means doing it right when no one is looking."
    Henry Ford

  •  17-11-2006, 12:44 20611 σε απάντηση της 20608

    Απ: Πως πιανεις το Exception thrown από ένα property που αλλαζει μέσο DataBinding

    Μπορείς να χρησιμοποιήσεις το BindingComplete event του Binding adminBind αντικειμένου. Σύμφωνα με το documentation:

    "Occurs when a binding operation is complete, such as when data is pushed to the control property from the data source or vice versa

    Remarks

    This event is raised under any of the following conditions:

    • Data from the data source is pushed onto the control property.

    • Data from the control property is pushed onto the data source.

    This event is raised at the completion of these operations, independent of the completion status. For example, if a binding operation binds a null value to a Value property, an exception is thrown, but the BindingComplete event still occurs. The handler of this event can take the appropriate action, based on the success, error, or exceptions in the binding process, by examining the BindingCompleteState property of the BindingCompleteEventArgs parameter."

    Ελπίζω αυτό να βοηθάει...



    MSc Konstantinos Pantos
    MCP Software Engineer
    http://blog.pantos.name
    http://kostas.pantos.name
  •  17-11-2006, 13:35 20620 σε απάντηση της 20611

    Απ: Πως πιανεις το Exception thrown από ένα property που αλλαζει μέσο DataBinding

    Spantos,

    Το έκανα και αυτό, το ίδιο προβλημα, δεν 'χτυπαει' το Event!!! και εγω πηγα μέσω της MSDN και τίποτα!!!

    thanx παντος για την Απάντηση

    Νασος
    "Success is the ability to go from one failure to another with no loss of enthusiasm."
    Winston Churchill

    "Quality means doing it right when no one is looking."
    Henry Ford

  •  17-11-2006, 13:54 20621 σε απάντηση της 20608

    Απ: Πως πιανεις το Exception thrown από ένα property που αλλαζει μέσο DataBinding

    Θα μπορούσες στη φόρμα σου να πιάσεις το Parse event του Binding, κι εκεί είτε:
    • Να καλείς την CanBeTheUserAdmin και αν επιστρέψει false να βγάζεις εσύ το μήνυμα και να κάνεις το ConvertEventArgs.Value πάλι false. Αυτό επαναλαμβάνει τον κώδικα του domain σου.
    • Να δοκιμάζεις μόνος σου σε ένα try/catch να θέσεις την τιμή, και στο catch να βγάζεις εσύ το μήνυμα και να κάνεις το ConvertEventArgs.Value πάλι false.
    Επίσης θα ήταν καλό να αλλάξεις το exception type σε κάτι πιο ειδικό από το Exception.


    Νατάσα Μανουσοπούλου
  •  17-11-2006, 15:09 20626 σε απάντηση της 20611

    Απ: Πως πιανεις το Exception thrown από ένα property που αλλαζει μέσο DataBinding

    Spot on!!!! mns

    Thnx a million

    Είναι το ΜΟΝΟ event που γίνετε Fire

    nice ;)
    "Success is the ability to go from one failure to another with no loss of enthusiasm."
    Winston Churchill

    "Quality means doing it right when no one is looking."
    Henry Ford

Προβολή Τροφοδοσίας RSS με μορφή XML
Με χρήση του Community Server (Commercial Edition), από την Telligent Systems