Exemple #1
0
        partial void btnCreateCar(Foundation.NSObject sender)
        {
            NSWindow w = tableView.Window;

            // try to end any editing that is taking place
            bool editingEnded = w.MakeFirstResponder(w);

            if (!editingEnded)
            {
                Console.WriteLine("Unable to end editing");
                return;
            }

            NSUndoManager undo = this.UndoManager;

            // Has an edit occurred already in this event?
            if (undo.GroupingLevel > 0)
            {
                // Close the last group
                undo.EndUndoGrouping();
                // Open a new group
                undo.BeginUndoGrouping();
            }

            // Create the object
            // Should be able to do arrayController.NewObject, but it returns an NSObjectController
            // not an NSObject and also causes an InvalidCastException
            // BUG: https://bugzilla.xamarin.com/show_bug.cgi?id=25620
//			var c = arrayController.NewObject;
            // Workaround - not available in Unified API... due to protection level.
//			Car c = (Car)Runtime.GetNSObject(Messaging.IntPtr_objc_msgSend(arrayController.Handle, Selector.GetHandle ("newObject")));
            // Plus I can't figure out how to get the Car object from NSObjectController. Ah, this is due to above bug.
            // Creating my own Person object instead
            Car c = new Car();

            // Add it to the content array of arrayController
            arrayController.AddObject(c);

            // Re-sort (in case the user has sorted a column)
            arrayController.RearrangeObjects();

            // Get the sorted array
            NSArray a = NSArray.FromNSObjects(arrayController.ArrangedObjects());

            // Find the object just added
            nint row = -1;

            for (nuint i = 0; i < a.Count; i++)
            {
                if (c == a.GetItem <Car>(i))
                {
                    row = (nint)i;
                    break;
                }
            }
            Console.WriteLine("Starting edit of {0} in row {1}", c, row);

            // Begin the edit of the first column
            tableView.EditColumn(0, row, null, true);
        }
Exemple #2
0
        partial void createEmployee(Foundation.NSObject sender)
        {
            NSUndoManager undo = this.UndoManager;

            // Has an edit occurred already in this event?
            if (undo.GroupingLevel > 0)
            {
                // Close the last group
                undo.EndUndoGrouping();
                // Open a new group
                undo.BeginUndoGrouping();
            }

            Person newEmployee = new Person();

            Console.WriteLine("Adding {0} to {1}", newEmployee, Employees);

            // Undo add
            NSArray args = NSArray.FromObjects(new object[] { newEmployee });

            undo.RegisterUndoWithTarget(this, new Selector("undoAdd:"), args);
            undo.SetActionname(NSBundle.MainBundle.LocalizedString("ADD_PERSON", null));

            Employees.Add(newEmployee);
            StartObservingPerson(newEmployee);
            tableView.ReloadData();

            int row = Employees.IndexOf(newEmployee);

            Console.WriteLine("Starting edit of {0} in row {1}", newEmployee, row);

            // Begin the edit of the first column
            tableView.SelectRow(row, false);
            tableView.EditColumn(0, row, null, true);
        }