![ישן](https://static.fresh.co.il/images/vBulletin/statusicon/post_old.gif)
29-05-2007, 09:06
|
|
|
חבר מתאריך: 03.04.06
הודעות: 31
|
|
בשמחה,
ישנם 2 דרכים,
הראשונה והפשוטה ביותר היא אם אתם משתמשים ב-visual studio 2005 כמובן, שם יש את האופציה בכל COMBOBOX של "auto complete"
במידה ואתם לא משתמשים בזה, כמוני,
יש לכתוב את הפונקציה הבאה:
קוד:
public static void AutoCompleteCombo(ComboBox cbo,KeyEventArgs e)
{
String sTypedText;
Int32 iFoundIndex;
Object oFoundItem;
String sFoundText ;
String sAppendText ;
//'Allow select keys without Autocompleting
switch (e.KeyCode)
{
case Keys.Back:
break;
case Keys.Left:
break;
case Keys.Right:
break;
case Keys.Tab:
break;
case Keys.Up:
break;
case Keys.Delete:
break;
case Keys.Down:
break;
}
//'Get the Typed Text and Find it in the list
sTypedText = cbo.Text;
iFoundIndex = cbo.FindString(sTypedText);
//'If we found the Typed Text in the list then Autocomplete
if (iFoundIndex >= 0)
{ //'Get the Item from the list (Return Type depends if Datasource was bound
//' or List Created)
oFoundItem = cbo.Items[iFoundIndex];
//'Use the ListControl.GetItemText to resolve the Name in case the Combo
//' was Data bound
sFoundText = cbo.GetItemText(oFoundItem);
//'Append then found text to the typed text to preserve case
sAppendText = sFoundText.Substring(sTypedText.Length);
cbo.Text = sTypedText.ToString() + sAppendText.ToString();
//'Select the Appended Text
cbo.SelectionStart = sTypedText.Length;
cbo.SelectionLength = sAppendText.Length;
}
}
ולאחר מכן יש לשלוח לפונקציה את הקומבו בוקס הרצוי באירוע של keyup לדוגמא:
AutoCompleteCombo (cmbMemory, e);
|