示例#1
0
        /// <summary>
        /// Inicjalizuje pola rozwijanej listy. Ustawia odpowiednie szerokości kolumn.
        /// </summary>
        /// <returns>Lista zainicjowanych pól. Elementy listy zawierają długi i krótki opis danego pola.</returns>
        private List<ComboBoxItem> InitializeItems()
        {
            List<ComboBoxItem> initializedItems = new List<ComboBoxItem>();
            IDataBase dataBase = null;
            int[] shortDescriptionWords = null;

            switch (tableName)
            {
                case "Collector":
                    dataBase = new Collectors();
                    shortDescriptionWords = new int[] { 1, 2 };
                    widthsOfColumns = new int[7];
                    break;
                case "Customer":
                    dataBase = new Customers();
                    shortDescriptionWords = new int[] { 1, 2 };
                    widthsOfColumns = new int[7];
                    break;
                case "Area":
                    dataBase = new Areas();
                    shortDescriptionWords = new int[] { 1 };
                    widthsOfColumns = new int[3];
                    break;
                case "Address":
                    dataBase = new Addresses();
                    shortDescriptionWords = new int[] { 1, 2, 3 };
                    widthsOfColumns = new int[4];
                    break;
            }

            List<string[]> itemList = dataBase.itemList;
            System.Drawing.Graphics g = comboBox.CreateGraphics();
            System.Drawing.Font f = comboBox.Font;

            string[] nullList = new string[widthsOfColumns.Length];
            for (int i = 0; i < nullList.Length; i++)
            {
                nullList[i] = String.Empty;
                widthsOfColumns[i] = 0;
            }

            initializedItems.Add(new ComboBoxItem(nullList, new int[] { 0 }));
            initializedItems.ElementAt(0).formattedLongItemDescription = String.Empty;

            foreach (string[] item in itemList)
            {

                ComboBoxItem comboBoxItem = new ComboBoxItem(item, shortDescriptionWords);

                for (int j = 0; j < widthsOfColumns.Length; j++)
                {
                    int newWidth = Convert.ToInt32(g.MeasureString(comboBoxItem.fields.ElementAt(j), f).Width);
                    if (newWidth > widthsOfColumns[j])
                        widthsOfColumns[j] = newWidth;
                }

                initializedItems.Add(comboBoxItem);
            }

            return initializedItems;
        }
示例#2
0
 /// <summary>
 /// Znajduje na liście elementów obiektu obiekt będący odpowiednikiem zaznaczonego na rozwijanej liście rekordu.
 /// </summary>
 /// <param name="item">"Aktualnie badany element listy.</param>
 /// <returns>true - badany obiekt jest poszukiwanym obiektem.</returns>
 private bool FindItem(ComboBoxItem item)
 {
     if (comboBox.SelectedIndex >= 0 && comboBox.Items.Count > 0)
         if (item.formattedLongItemDescription == comboBox.Items[comboBox.SelectedIndex].ToString())
             return true;
     return false;
 }