System.Windows.Forms.ListBox.FindString C# (CSharp) Method

FindString() public method

public FindString ( string s, int startIndex ) : int
s string
startIndex int
return int
		public int FindString (string s,  int startIndex)
		{
			if (Items.Count == 0)
				return -1; // No exception throwing if empty

			if (startIndex < -1 || startIndex >= Items.Count)
				throw new ArgumentOutOfRangeException ("Index of out range");

			startIndex = (startIndex == Items.Count - 1) ? 0 : startIndex + 1;

			int i = startIndex;
			while (true) {
				string text = GetItemText (Items [i]);
				if (CultureInfo.CurrentCulture.CompareInfo.IsPrefix (text, s,
						CompareOptions.IgnoreCase))
					return i;

				i = (i == Items.Count - 1) ? 0 : i + 1;
				if (i == startIndex)
					break;
			}

			return NoMatches;
		}

Same methods

ListBox::FindString ( String s ) : int

Usage Example

示例#1
0
        /// <summary>
        /// Sets the selected index text
        /// </summary>
        /// <param name="indexText">text to select</param>
        public void SelectText(string indexText)
        {
            tbLookfor.Text = indexText.Trim();
            int idx = lbIndex.FindString(indexText, 0);

            lbIndex.SelectedIndex = idx;
        }
All Usage Examples Of System.Windows.Forms.ListBox::FindString