public void Populate()
 {
     if (AddressDefinition != null && controlCreated)
     {
         ControlCollection coll = AddressDefinition.AddressGrid.Controls;
         Array.ForEach(coll.ToArray(), a => a.ResolveBinding(coll, DataContext));
     }
     else
     {
         deferPopulateFields = true;
     }
 }
        public object CreateAddressFromControl()
        {
            object dataContext = DataContext;

            if (dataContext != null && AddressDefinition != null)
            {
                ControlCollection coll =
                    AddressDefinition.AddressGrid.Controls;
                foreach (Control r in coll)
                {
                    if (r.Editable)
                    {
                        dataContext = r.SetValue(dataContext);
                    }
                    r.PopulateValueField();
                }
            }
            return(dataContext);
        }
        public bool Validate()
        {
            if (AddressDefinition != null && controlCreated)
            {
                List <string>     errors = null;
                ControlCollection coll   = AddressDefinition.AddressGrid.Controls;
                Array.ForEach(coll.ToArray(), a => a.Validate(ref errors));

                //TODO: this actually does nothing!
                displayValidationMessages(errors);

                if (errors.Count > 0)
                {
                    ErrorList = errors;
                    return(false);
                }
                return(!(errors != null && errors.Count > 0));
            }
            return(true);
        }
        private void createControls()
        {
            if (AddressDefinition != null)
            {
                HtmlGenericControl row  = null;
                ControlCollection  coll = AddressDefinition.AddressGrid.Controls;
                coll.SortControls();

                // Reading the resx to create the control
                var         reader      = new AddressResxReader();
                AddressResx addressResx = reader.GetAddressResx(Thread.CurrentThread.CurrentCulture.Name);
                var         rowNumber   = -1;
                foreach (int r in coll.Select(s => s.Row).Distinct())
                {
                    if (rowNumber != r)
                    {
                        var colNum = coll.Where(c => c.Row == r).Select(a => a.Column).Distinct().ToList();
                        _containerTable.Controls.Add(row = new HtmlGenericControl("div"));
                        rowNumber = r + 1;
                        var colNumRow = coll.Where(c => c.Row == rowNumber).Select(a => a.Column).Distinct().ToList();
                        if (colNumRow.Count > colNum.Count)
                        {
                            colNum = colNumRow;
                        }

                        var childNumber = 1;
                        foreach (int column in colNum)
                        {
                            if (colNum.Count() > 1)
                            {
                                var rowChild = new HtmlGenericControl("div");
                                row.Attributes.Add("class", "row-group " + "cols-" + colNum.Count().ToString());
                                rowChild.Attributes.Add("class", "inline");

                                if (childNumber == colNum.Count())
                                {
                                    rowChild.Attributes.Add("class", "inline last-child");
                                }
                                var lstControls = coll.Where(p => (p.Row == r || p.Row == rowNumber) && p.Column == column).Select(a => a).ToList();

                                rowChild.Attributes.Add("name", lstControls[0].Name.Contains("Spacer") ? "" : lstControls[0].Name.ToString());
                                foreach (Control c in lstControls)
                                {
                                    c.CreateUIControl(rowChild, DataContext, addressResx);
                                }
                                row.Controls.Add(rowChild);
                                childNumber++;
                            }
                            else
                            {
                                var lstControls = coll.Where(p => (p.Row == r || p.Row == rowNumber) && p.Column == column).Select(a => a).ToList();
                                row.Attributes.Add("name", lstControls[0].Name.Contains("Spacer") ? "" : lstControls[0].Name.ToString());
                                foreach (Control c in lstControls)
                                {
                                    c.CreateUIControl(row, DataContext, addressResx);
                                }
                            }
                        }
                    }
                    else
                    {
                        rowNumber = -1;
                    }
                }
                if (coll.Exists(p => p.Editable == true))
                {
                    _editMode = Mode.Edit;
                }
                AddressDefinition.AddressGrid.ResovleBinding(DataContext);
                controlCreated = true;
            }
        }