Beispiel #1
0
            public NPersonInfo(string name, ENGender gender)
            {
                Name   = name;
                Gender = gender;

                // random birthday of 20-50 year olds
                int days = Random.Next(30 * 365) + 20 * 365;

                Birthday = DateTime.Now - new TimeSpan(days, 0, 0, 0);

                // random country
                Country = (ENCountry)Random.Next(NEnum.GetValues(typeof(ENCountry)).Length);

                // random phone
                int areaCode        = Random.Next(999);
                int firstPhonePart  = Random.Next(999);
                int secondPhonePart = Random.Next(9999);

                Phone = String.Format("({0})-{1}-{2}", areaCode.ToString("000"), firstPhonePart.ToString("000"), secondPhonePart.ToString("0000"));

                // email
                Email = Name.ToLower().Replace(" ", ".") + "@domain.com";
            }
        protected override NWidget CreateExampleContent()
        {
            // create a view and get its grid
            m_View = new NTableGridView();
            NTableGrid grid = m_View.Grid;

            // bind the grid to the data source
            grid.DataSource = NDummyDataSource.CreatePersonsDataSource();

            // configure the master grid
            grid.AllowEdit = false;

            // assign some icons to the columns
            for (int i = 0; i < grid.Columns.Count; i++)
            {
                NDataColumn dataColumn = grid.Columns[i] as NDataColumn;
                if (dataColumn == null)
                {
                    continue;
                }

                NImage image = null;
                switch (dataColumn.FieldName)
                {
                case "Name":
                    image = NResources.Image__16x16_Contacts_png;
                    break;

                case "Gender":
                    image = NResources.Image__16x16_Gender_png;
                    break;

                case "Birthday":
                    image = NResources.Image__16x16_Birthday_png;
                    break;

                case "Country":
                    image = NResources.Image__16x16_Globe_png;
                    break;

                case "Phone":
                    image = NResources.Image__16x16_Phone_png;
                    break;

                case "Email":
                    image = NResources.Image__16x16_Mail_png;
                    break;

                default:
                    continue;
                }

                // NOTE: The CreateHeaderContentDelegate is invoked whenever the Title changes or the UpdateHeaderContent() is called.
                // you can use this event to create custom column header content
                dataColumn.CreateHeaderContentDelegate = delegate(NColumn theColumn)
                {
                    NPairBox pairBox = new NPairBox(image, theColumn.Title, ENPairBoxRelation.Box1BeforeBox2);
                    pairBox.Spacing = 2;
                    return(pairBox);
                };
                dataColumn.UpdateHeaderContent();
            }

            // create the custom detail that creates a widget displaying information about the row.
            // NOTE: The widget is created by the OnCustomDetailCreateWidget event handler.
            NMasterDetails masterDetails = grid.MasterDetails;

            NCustomDetail customDetail = new NCustomDetail();

            masterDetails.Details.Add(customDetail);

            customDetail.CreateWidgetDelegate = delegate(NCustomDetailCreateWidgetArgs arg)
            {
                // get information about the data source row
                string    name     = (string)arg.DataSource.GetValue(arg.RowIndex, "Name");
                ENGender  gender   = (ENGender)arg.DataSource.GetValue(arg.RowIndex, "Gender");
                DateTime  birthday = (DateTime)arg.DataSource.GetValue(arg.RowIndex, "Birthday");
                ENCountry country  = (ENCountry)arg.DataSource.GetValue(arg.RowIndex, "Country");
                string    phone    = (string)arg.DataSource.GetValue(arg.RowIndex, "Phone");
                string    email    = (string)arg.DataSource.GetValue(arg.RowIndex, "Email");

                // display the information as a widget
                NPairBox namePair     = new NPairBox("Name:", name);
                NPairBox genderPair   = new NPairBox("Gender:", gender.ToString());
                NPairBox birthdayPair = new NPairBox("Birthday:", birthday.ToString());
                NPairBox countryPair  = new NPairBox("Country:", country.ToString());
                NPairBox phonePair    = new NPairBox("Phone:", phone.ToString());
                NPairBox emailPair    = new NPairBox("Email:", email.ToString());

                NImageBox image = new NImageBox();
                switch (gender)
                {
                case ENGender.Male:
                    image.Image = Nevron.Nov.Examples.NResources.Image__256x256_MaleIcon_jpg;
                    break;

                case ENGender.Female:
                    image.Image = Nevron.Nov.Examples.NResources.Image__256x256_FemaleIcon_jpg;
                    break;

                default:
                    break;
                }

                NStackPanel infoStack = new NStackPanel();
                infoStack.VerticalSpacing = 2.0d;
                infoStack.Add(namePair);
                infoStack.Add(genderPair);
                infoStack.Add(birthdayPair);
                infoStack.Add(countryPair);
                infoStack.Add(phonePair);
                infoStack.Add(emailPair);

                NDockPanel dock = new NDockPanel();
                dock.Add(image, ENDockArea.Left);
                dock.Add(infoStack, ENDockArea.Center);

                // assign the widget to the event arguments.
                return(dock);
            };

            return(m_View);
        }