Hi, I've just started working with MT and Dialog and work has been rapid and
painless up until now.

Basically I'm working with two SQLite tables. Lets call them Heads and Rows
with a one to many relation. 

I'm building the “Rows view” using an inherited DVC-class.
In LoadView I'm loading one section with a custom element, a
ScannerEntryElement, followed by a section with SQLite table row elements.
Every element in the last section holds a database object that I use for
cell rendering and database operations.

The ScannerEntryElement scans a barcode and looks up the corresponding
element from the section below and increments a counter in the db object.
Works perfectly...the first time the view is loaded!

Here's the problem. The second time,  if I'm loading the  view with rows
from another head, the ScannerEntryElement still thinks the rows in the
section below are the same as the first time(same root and section) , even
though I visually can confirm that the correct rows have been loaded in the
section.

I have even tried sending a section reference(to the current row section) to
the scan delegate but no luck. 

Code bellow. The Scan delegate is implemented within the inherited DVC.

A little help please!



public override void LoadView () {
        Root = new RootElement("Delivery");
        Section top = new Section();
        var scanElement = new ScannerEntryElement("EAN", "Scan here", "", Scan);
        top.Add(scanElement);
        section = new Section("Rows");
        foreach (DeliveryOutRow row in
Database.Main.Table<DeliveryOutRow>().Where(arg => arg.DeliveryNo == n)) {
                        var element = new DeliveryOutRowElement (row);
                        element.BackgroundColor = row.PickedQty < 
row.SalesOrderQty ? UIColor.Red
: UIColor.Green;
                        section.Add (element);
                };
        
        Root.Add(top);
        Root.Add(section);
        base.LoadView();
}

// <summary>
/// Scan the specified ean.
/// </summary>
/// 
/// Ean.
/// 
private void Scan(string ean) {
        Section section = Root.SectionList [1];  <-- Wrong section, Allways the
same
        foreach (Element e in section.Elements) {
                if (ean.Equals(((DeliveryOutRowElement)e).Row.EAN )) {
                        ((DeliveryOutRowElement)e).Row.PickedQty += 1;
                        Database.Main.Update(((DeliveryOutRowElement)e).Row);
                        ReloadData(); // Not working. View not updated.
                }
        }
}

public class ScannerEntryElement : MonoTouch.Dialog.EntryElement {
        private ScanDelegate ScanAction;
        
        private string EAN = "";
        private Section section;
        public AEntryElement (string caption, string placeholder, string value,
ScanDelegate ScanAction) : base(caption, placeholder, value) {
                this.ScanAction = ScanAction;
        }
        
        protected override UITextField CreateTextField (RectangleF frame) {
                UITextField textField = base.CreateTextField(frame);
                NSNotificationCenter.DefaultCenter.AddObserver(
                        UITextField.TextFieldTextDidChangeNotification, 
(notification) => {
                        string s = 
((UITextField)notification.Object).Text.ToString();
                        if (s.Length == 13) {
                                EAN = s;
                                ((UITextField)notification.Object).Text = "";
                                ScanAction(EAN);
                        }
                });
                return textField;       
        }

        private class ATextField : UITextField {
                public ATextField() : base() {
                        KeyboardType = UIKeyboardType.NumberPad;
                }
        }
}

--
View this message in context: 
http://monotouch.2284126.n4.nabble.com/Working-with-Dialog-tp4654411.html
Sent from the MonoTouch mailing list archive at Nabble.com.
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to