Ejemplo n.º 1
0
        private void OnCountryNameDataBindingCreateItemNode(NCreateItemNodeEventArgs <NComboBoxItem, NCountry> args)
        {
            // Create a combo box item for the current country
            NCountry country = args.Item;

            args.Node = new NComboBoxItem(country.Name);
        }
Ejemplo n.º 2
0
        private void OnTextBoxTextChanged(NValueChangeEventArgs arg)
        {
            string   text    = (string)arg.NewValue;
            NCountry country = GetCountryByName(text, m_CaseSensitiveCheckBox.Checked);

            if (country != null)
            {
                m_EventsLog.LogEvent("Selected country: " + country.Name);
            }
        }
Ejemplo n.º 3
0
        private NCountry GetCountryByName(string str, bool caseSensitive)
        {
            StringComparison comparison = caseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;

            for (int i = 0, count = m_Countries.Count; i < count; i++)
            {
                NCountry country = m_Countries[i];
                if (String.Equals(str, country.Name, comparison))
                {
                    return(country);
                }
            }

            return(null);
        }
Ejemplo n.º 4
0
        private void OnCountryDataBindingCreateItemNode(NCreateItemNodeEventArgs <NComboBoxItem, NCountry> args)
        {
            NCountry country = args.Item;

            // Create a stack panel
            NStackPanel stack = new NStackPanel();

            stack.Padding = new NMargins(3);
            stack.Tag     = country;

            // Create the flag image box and the country name label
            NLabel countryLabel = new NLabel(country.Name);

            countryLabel.VerticalPlacement = ENVerticalPlacement.Center;
            countryLabel.Font = new NFont(NFontDescriptor.DefaultSansFamilyName, 10, ENFontStyle.Bold);

            NImageBox imageBox = new NImageBox(country.Flag);

            imageBox.VerticalPlacement   = ENVerticalPlacement.Center;
            imageBox.HorizontalPlacement = ENHorizontalPlacement.Left;

            NPairBox pairBox = new NPairBox(imageBox, countryLabel);

            pairBox.Spacing = 3;
            stack.Add(pairBox);

            // Create the capital label
            NLabel capitalLabel = new NLabel("Capital: " + country.Capital);

            stack.Add(capitalLabel);

            // Create the currency label
            NLabel currencyLabel = new NLabel("Currency: " + country.CurrencyName + ", " +
                                              country.CurrencyCode);

            stack.Add(currencyLabel);

            // Create a combo box item to host the created widget
            NComboBoxItem comboBoxItem = new NComboBoxItem(stack);

            comboBoxItem.Text = country.Name;
            args.Node         = comboBoxItem;
        }
Ejemplo n.º 5
0
        private void OnComboBoxSelectedIndexChanged(NValueChangeEventArgs args)
        {
            if (m_bSelectionUpdating)
            {
                m_bSelectionUpdating = false;
                return;
            }

            // Get the list box and the other list box
            int       selectedIndex = (int)args.NewValue;
            NComboBox comboBox      = (NComboBox)args.TargetNode;
            NComboBox otherComboBox = comboBox == m_ComboBox ? m_AdvancedComboBox : m_ComboBox;

            // Log the selection
            NComboBoxItem selectedItem = comboBox.SelectedItem;
            NCountry      country      = NNodeCollectionDataBinding <NComboBoxItemCollection, NComboBoxItem, NCountry> .GetDataBoundItem(selectedItem);

            m_EventsLog.LogEvent("'" + country.Name + "' selected");

            // Synchronize the selection between the two list boxes
            m_bSelectionUpdating        = true;
            otherComboBox.SelectedIndex = selectedIndex;
        }
Ejemplo n.º 6
0
        private void OnListBoxItemSelected(NSelectEventArgs <NListBoxItem> args)
        {
            if (m_bSelectionUpdating)
            {
                m_bSelectionUpdating = false;
                return;
            }

            // Get the list box and the other list box
            NListBox listBox      = (NListBox)args.Item.OwnerListBox;
            NListBox otherListBox = listBox == m_ListBox ? m_AdvancedListBox : m_ListBox;

            // Log the selection
            NListBoxItem selectedItem = listBox.Selection.FirstSelected;
            NCountry     country      = NNodeCollectionDataBinding <NListBoxItemCollection, NListBoxItem, NCountry> .GetDataBoundItem(selectedItem);

            m_EventsLog.LogEvent("'" + country.Name + "' selected");

            // Synchronize the selection between the two list boxes
            m_bSelectionUpdating = true;
            int selectedIndex = listBox.Items.IndexOf(selectedItem);

            otherListBox.Selection.SingleSelect(otherListBox.Items[selectedIndex]);
        }
Ejemplo n.º 7
0
        private NList <NCountry> LoadCountryData()
        {
            // Get the country list XML stream
            Stream stream = NResources.Instance.GetResourceStream("RSTR_CountryList_xml");

            // Load an xml document from the stream
            NXmlDocument xmlDocument = NXmlDocument.LoadFromStream(stream);

            // Process it
            NXmlNode         rows      = xmlDocument.GetChildAt(0).GetChildAt(1);
            NList <NCountry> countries = new NList <NCountry>();

            for (int i = 0, countryCount = rows.ChildrenCount; i < countryCount; i++)
            {
                NXmlNode row = rows.GetChildAt(i);

                // Get the country name
                NCountry country = new NCountry(GetValue(row.GetChildAt(1)));
                if (String.IsNullOrEmpty(country.Name))
                {
                    continue;
                }

                // Get the country's capital
                country.Capital = GetValue(row.GetChildAt(6));
                if (String.IsNullOrEmpty(country.Capital))
                {
                    continue;
                }

                // Get the country's currency
                country.CurrencyCode = GetValue(row.GetChildAt(7));
                country.CurrencyName = GetValue(row.GetChildAt(8));
                if (String.IsNullOrEmpty(country.CurrencyCode) || String.IsNullOrEmpty(country.CurrencyName))
                {
                    continue;
                }

                // Get the country code (ISO 3166-1 2 Letter Code)
                country.Code = GetValue(row.GetChildAt(10));
                if (String.IsNullOrEmpty(country.Code))
                {
                    continue;
                }

                // Get the country flag
                string            flagResourceName = "RIMG_CountryFlags_" + country.Code.ToLower() + "_png";
                NEmbeddedResource flagResource     = NResources.Instance.GetResource(flagResourceName);
                if (flagResource == null)
                {
                    continue;
                }

                country.Flag = new NImage(new NEmbeddedResourceRef(flagResource));

                // Add the country to the list
                countries.Add(country);
            }

            // Sort the countries by name and return them
            countries.Sort();
            return(countries);
        }