PDA

View Full Version : چگونه گی جستجو در لبست باکس...



tigervb6
سه شنبه 02 مهر 1392, 16:40 عصر
سلام دوستان
کسی می دونه چه جوری می شه یه عبارت را از بین ایتم های لیست باکس جستجو کرد
بعد اگه وجود داشت ایندکس اون ایتم رو به دست بیاره
:متفکر:
:متفکر:

forodo
سه شنبه 02 مهر 1392, 17:16 عصر
private void button3_Click(object sender, EventArgs e)
{
// Set the search string:
string myString = textBox1.Text;
// Search starting from index -1:
int index = listBox1.FindString(myString, -1);
if (index != -1)
{
// Select the found item:
listBox1.SetSelected(index, true);
// Send a success message:
MessageBox.Show("Found the item \"" + myString + "\" at index: " + index);
}
else
{
MessageBox.Show("Item not found.");
}
}

aliagamon
سه شنبه 02 مهر 1392, 17:23 عصر
از این تابع استفاده کن:

private void FindAllOfMyString(string searchString)
{

ListBox1.SelectionMode = SelectionMode.MultiExtended;
ListBox1.ClearSelected();

int x = -1;

if (searchString.Length != 0)
{
do
{

x = ListBox1.FindString(searchString, x);

if (x != -1)
{

if (ListBox1.SelectedIndices.Count > 0)
{
if (x == ListBox1.SelectedIndices[0])
return;
}

ListBox1.SetSelected(x, true);
}
} while (x != -1);
}
}

تو رویداد textchanged بزار و هربار ورودی بهش متن تکست باکستو بده....