/// <summary>
 /// Переместить фильтр с заданным id  в коллекции в указанную позицию
 /// </summary>
 /// <param name="id">id фильтра</param>
 /// <param name="index">Позиция в списке</param>
 public void MoveFilter(string id, int index)
 {
     if (index >= 0 && index < filters.Values.Count)
     {
         Filter f = (Filter)filters[id];
         filters.Remove(id);
         filters.Insert(index, f.Id, f);
         Invalidate();
     }
 }
 static void Main(string[] args)
 {
     System.Collections.Specialized.OrderedDictionary orderedDictionary = new System.Collections.Specialized.OrderedDictionary();
     orderedDictionary.Add("Test1", "Test@123");
     orderedDictionary.Add("Admin", "Admin@123");
     orderedDictionary.Add("Temp", "Temp@123");
     orderedDictionary.Add("Demo", "Demo@123");
     orderedDictionary.Add("Test2", "Test2@123");
     orderedDictionary.Remove("Admin");
     if (orderedDictionary.Contains("Admin"))
     {
         Console.WriteLine("UserName already Esists");
     }
     else
     {
         orderedDictionary.Add("Admin", "Admin@123");
         Console.WriteLine("User added succesfully.");
     }
     // Insert a new key to the beginning of the OrderedDictionary
     orderedDictionary.Insert(0, "Test3", "Test3@123");
     // Modify the value of the entry with the key "Test1"
     orderedDictionary["Test1"] = "Test1@333";
     // Get a collection of the keys.
     Console.WriteLine("UserName" + ": " + "Password");
     foreach (DictionaryEntry entry in orderedDictionary)
     {
         Console.WriteLine(entry.Key + ": " + entry.Value);
     }
     String[] myKeys   = new String[orderedDictionary.Count];
     String[] myValues = new String[orderedDictionary.Count];
     orderedDictionary.Keys.CopyTo(myKeys, 0);
     orderedDictionary.Values.CopyTo(myValues, 0);
     Console.WriteLine("");
     // Displays the contents of the OrderedDictionary
     Console.WriteLine(" INDEX KEY  VALUE");
     for (int i = 0; i < orderedDictionary.Count; i++)
     {
         Console.WriteLine("   {0} {1} {2}",
                           i, myKeys[i], myValues[i]);
     }
     Console.WriteLine();
     Console.ReadKey();
 }
        /// <summary>
        /// Populates the filters dictionary with formatted and unformatted string
        /// representations of each unique value in the column, accounting for all
        /// filters except the current column's. Also adds special filter options.
        /// </summary>
        private void PopulateFilters()
        {
            ArrayList list = null;
            Boolean   containsBlanks;
            Boolean   containsNonBlanks;
            String    oldFilter = "";

            // Continue only if there is a DataGridView.
            if (this.DataGridView == null)
            {
                return;
            }

            // Cast the data source to a BindingSource.
            BindingSource data = this.DataGridView.DataSource as BindingSource;

            Debug.Assert((data != null && data.SupportsFiltering && OwningColumn != null) || (Retriever != null),
                         "DataSource is not a BindingSource, or does not support filtering, or OwningColumn is null");

            containsBlanks    = false;
            containsNonBlanks = false;

            // Reset the filters dictionary and initialize some flags
            // to track whether special filter options are needed.
            filters.Clear();

            if (data != null)
            {
                // Prevent the data source from notifying the DataGridView of changes.
                data.RaiseListChangedEvents = false;

                // Cache the current BindingSource.Filter value and then change
                // the Filter property to temporarily remove any filter for the
                // current column.

                oldFilter   = data.Filter;
                data.Filter = FilterWithoutCurrentColumn(oldFilter);

                // Initialize an ArrayList to store the values in their original
                // types. This enables the values to be sorted appropriately.
                list = new ArrayList(data.Count);

                // Retrieve each value and add it to the ArrayList if it isn't
                // already present.
                foreach (Object item in data)
                {
                    Object value = null;

                    // Use the ICustomTypeDescriptor interface to retrieve properties
                    // if it is available; otherwise, use reflection. The
                    // ICustomTypeDescriptor interface is useful to customize
                    // which values are exposed as properties. For example, the
                    // DataRowView class implements ICustomTypeDescriptor to expose
                    // cell values as property values.
                    //
                    // Iterate through the property names to find a case-insensitive
                    // match with the DataGridViewColumn.DataPropertyName value.
                    // This is necessary because DataPropertyName is case-
                    // insensitive, but the GetProperties and GetProperty methods
                    // used below are case-sensitive.
                    ICustomTypeDescriptor ictd = item as ICustomTypeDescriptor;
                    if (ictd != null)
                    {
                        PropertyDescriptorCollection properties = ictd.GetProperties();
                        foreach (PropertyDescriptor property in properties)
                        {
                            if (String.Compare(this.OwningColumn.DataPropertyName,
                                               property.Name, true /*case insensitive*/,
                                               System.Globalization.CultureInfo.InvariantCulture) == 0)
                            {
                                value = property.GetValue(item);
                                break;
                            }
                        }
                    }
                    else
                    {
                        PropertyInfo[] properties = item.GetType().GetProperties(
                            BindingFlags.Public | BindingFlags.Instance);
                        foreach (PropertyInfo property in properties)
                        {
                            if (String.Compare(this.OwningColumn.DataPropertyName,
                                               property.Name, true /*case insensitive*/,
                                               System.Globalization.CultureInfo.InvariantCulture) == 0)
                            {
                                value = property.GetValue(item, null /*property index*/);
                                break;
                            }
                        }
                    }

                    // Skip empty values, but note that they are present.
                    if (value == null || value == DBNull.Value)
                    {
                        containsBlanks = true;
                        continue;
                    }

                    // Add values to the ArrayList if they are not already there.
                    if (!list.Contains(value))
                    {
                        list.Add(value);
                    }
                }
            }
            else
            {
                // Initialize an ArrayList to store the values in their original
                // types. This enables the values to be sorted appropriately.

                DataTable dataTable = new DataTable();

                IBE.Program.DBCon.Execute(String.Format("{0} {1} {2}", RetrieverSQLSelect, Retriever.BaseStatement, Retriever.GetWhereStatement(this.OwningColumn.Name)), dataTable);

                list = new ArrayList(dataTable.Rows.Count);

                foreach (DataRow selectableItem in dataTable.Rows)
                {
                    list.Add(selectableItem[0]);
                }
            }

            // Sort the ArrayList. The default Sort method uses the IComparable
            // implementation of the stored values so that string, numeric, and
            // date values will all be sorted correctly.
            list.Sort();

            // Convert each value in the ArrayList to its formatted representation
            // and store both the formatted and unformatted string representations
            // in the filters dictionary.
            foreach (Object value in list)
            {
                // Use the cell's GetFormattedValue method with the column's
                // InheritedStyle property so that the dropDownListBox format
                // will match the display format used for the column's cells.
                String formattedValue       = null;
                DataGridViewCellStyle style = OwningColumn.InheritedStyle;
                formattedValue = (String)GetFormattedValue(value, -1, ref style,
                                                           null, null, DataGridViewDataErrorContexts.Formatting);

                if (String.IsNullOrEmpty(formattedValue))
                {
                    // Skip empty values, but note that they are present.
                    containsBlanks = true;
                }
                else if (!filters.Contains(formattedValue))
                {
                    // Note whether non-empty values are present.
                    containsNonBlanks = true;

                    // For all non-empty values, add the formatted and
                    // unformatted string representations to the filters
                    // dictionary.
                    filters.Add(formattedValue, value.ToString());
                }
            }

            if (data != null)
            {
                // Restore the filter to the cached filter string and
                // re-enable data source change notifications.
                if (oldFilter != null)
                {
                    data.Filter = oldFilter;
                }
                data.RaiseListChangedEvents = true;
            }

            // Add special filter options to the filters dictionary
            // along with null values, since unformatted representations
            // are not needed.
            filters.Insert(0, "(All)", null);
            if (containsBlanks && containsNonBlanks)
            {
                filters.Add("(Blanks)", null);
                filters.Add("(NonBlanks)", null);
            }
        }