System.Windows.Forms.ListView.EnsureVisible C# (CSharp) Method

EnsureVisible() public method

public EnsureVisible ( int index ) : void
index int
return void
		public void EnsureVisible (int index)
		{
			if (index < 0 || index >= items.Count || scrollable == false || updating)
				return;

			Rectangle view_rect = item_control.ClientRectangle;
			// Avoid direct access to items in virtual mode, and use item bounds otherwise, since we could have reordered items
			Rectangle bounds = virtual_mode ? new Rectangle (GetItemLocation (index), ItemSize) : items [index].Bounds;

			if (view == View.Details && header_style != ColumnHeaderStyle.None) {
				view_rect.Y += header_control.Height;
				view_rect.Height -= header_control.Height;
			}

			if (view_rect.Contains (bounds))
				return;

			if (View != View.Details) {
				if (bounds.Left < 0)
					h_scroll.Value += bounds.Left;
				else if (bounds.Right > view_rect.Right)
					h_scroll.Value += (bounds.Right - view_rect.Right);
			}

			if (bounds.Top < view_rect.Y)
				v_scroll.Value += bounds.Top - view_rect.Y;
			else if (bounds.Bottom > view_rect.Bottom)
				v_scroll.Value += (bounds.Bottom - view_rect.Bottom);
		}

Usage Example

示例#1
0
        /// <summary>
        /// 确定索引	{1、按第一列索引;2、如果没有则按照第二列索引;}
        /// </summary>
        private void Index(string strInput)
        {
            if (txbDisplay.Text.Trim() == "")
            {
                return;
            }
            lsvContext.SelectedItems.Clear();

            string strTem = "";
            int    i;

            for (int i1 = 0; i1 < lsvContext.Columns.Count; i1++)
            {
                if (IsIndex(i1))               //判断本字段是否要索引
                {
                    foreach (ListViewItem lsvItem in lsvContext.Items)
                    {
                        strTem = lsvItem.SubItems[i1].Text.ToLower();
                        i      = strTem.IndexOf(strInput.ToLower());
                        if (i == 0)
                        {
                            lsvItem.Selected = true;
                            lsvContext.EnsureVisible(lsvItem.Index);
                            break;
                        }
                    }
                    if (lsvContext.SelectedItems.Count > 0)
                    {
                        break;
                    }
                }
            }
        }
All Usage Examples Of System.Windows.Forms.ListView::EnsureVisible
ListView