Couple of suggestions:
1. put your sections (in LoadView) in the class, and refer to them by name. eg:
Section top, section;
in LoadView:
top = new Section(...)
etc
then you don't need to find them in the scan method.
2. try scan like this:
private void Scan(string ean) {
//section is now "global" to the class
foreach (Element e in section.Elements) {
DeliveryOutRowElement dorow = e as DeliveryOutRowElement;
if (dorow != null) {
if (ean.Equals(dorow.Row.EAN )) {
dorow.Row.PickedQty += 1;
Database.Main.Update(dorow.Row);
Root.Reload(dorow, UITableViewRowAnimation.None);
}
}
}
}
You could also NOT do the Reload at the end, and call this outside the look:
Root.Reload(section, UITableViewRowAnimation.None);
Check out the other options for the second param, too - you can do
fades, animations etc. Some are ugly and you dont want them, but try
them out to see what they do.
3. Not essential, but to keep things all together:
element.BackgroundColor = row.PickedQty < row.SalesOrderQty ? UIColor.Red
: UIColor.Green;
put this IN the element - make it work out the color, so it's always
in one place. Options, but cleaner (IMO). If you are reusing this cell
somewhere else, then.... maybe not :)
Hope that helps.
N
On Fri, May 25, 2012 at 3:19 PM, appli <[email protected]> wrote:
> 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
--
Nic Wise
t. +44 7788 592 806 | @fastchicken | http://www.linkedin.com/in/nicwise
b. http://www.fastchicken.co.nz/
Earnest: Self-employed? Track your business expenses and income.
http://earnestapp.com
Nearest Bus: find when the next bus is coming to your stop. http://goo.gl/Vcz1p
mobileAgent (for FreeAgent): get your accounts in your pocket.
http://goo.gl/IuBU
Trip Wallet: Keep track of your budget on the go: http://goo.gl/ePhKa
London Bike App: Find the nearest Boris Bike, and get riding! http://goo.gl/Icp2
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch