EnsureVisible() public method

public EnsureVisible ( int index ) : void
index int
return void
Example #1
0
        private void CreateListBox(string listFilter)
        {
            if (listBox != null)
            {
                listBox = null;
                return;
            }

            if (!listBoxOpened)
            {
                listBox                = new ListBox();
                listBox.Font           = Font;
                listBox.uwfContext     = true;
                listBox.Width          = Width;
                listBox.ItemHeight     = ItemHeight;
                listBox.Height         = listBox.ItemHeight * (Items.Count > MaxDropDownItems ? MaxDropDownItems : Items.Count);
                listBox.uwfWrapText    = false;
                listBox.uwfShadowBox   = true;
                listBox.uwfBorderColor = listBox.uwfBorderSelectColor;
                if (listBox.Height < listBox.ItemHeight)
                {
                    listBox.Height = listBox.ItemHeight;
                }

                bool selectedIndexChanged = false;
                for (int i = 0; i < Items.Count; i++)
                {
                    var item = Items[i];
                    if (DropDownStyle == ComboBoxStyle.DropDownList || String.IsNullOrEmpty(listFilter))
                    {
                        listBox.Items.Add(item);
                    }
                    else
                    {
                        var itemString = item.ToString();
                        if (!itemString.ToLower().Contains(listFilter.ToLower()))
                        {
                            continue;
                        }

                        listBox.Items.Add(item);
                        if (itemString != listFilter)
                        {
                            continue;
                        }

                        listBox.SelectedIndex = i;
                        selectedIndexChanged  = true;
                    }
                }
                for (int i = 0; i < Items.Count; i++)
                {
                    if (Items.IsDisabled(i))
                    {
                        listBox.Items.Disable(i);
                    }
                }

                if (selectedIndexChanged == false)
                {
                    listBox.SelectedIndex = SelectedIndex;
                    listBox.EnsureVisible();
                }

                var gpoint = PointToScreen(Point.Empty);
                listBox.Location  = new Point(gpoint.X, gpoint.Y + Height);
                listBox.MouseUp  += ListBoxOnMouseUp;
                listBox.KeyDown  += ListBoxOnKeyDown;
                listBox.Disposed += ListBoxOnDisposed;

                OnDropDown(EventArgs.Empty);
            }
            else
            {
                listBoxOpened = false;
            }
        }