Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. void populateList()
  2. {
  3. this->storageList = gcnew Generic::List<String ^>;
  4. storageList->Add("January");
  5. storageList->Add("February");
  6. storageList->Add("March");
  7. storageList->Add("April");
  8. storageList->Add("May");
  9. storageList->Add("June");
  10. storageList->Add("July");
  11. storageList->Add("August");
  12. storageList->Add("September");
  13. storageList->Add("October");
  14. storageList->Add("November");
  15. storageList->Add("December");
  16. }
  17.  
  18. void handleTextChange()
  19. {
  20. String ^ searchText = toolStripComboBox->Text;
  21. toolStripComboBox->Items->Clear();
  22. Cursor->Current = Cursors::Default;
  23.  
  24. if(searchText != "")
  25. {
  26. toolStripComboBox->DroppedDown = true;
  27. Regex ^ searchRegex = gcnew Regex("(?i).*"+searchText+".*");
  28. for(int i = 0; i<storageList->Count; i++)
  29. {
  30. Match ^ m = searchRegex->Match(storageList[i]);
  31. if(m->Success)
  32. {
  33. toolStripComboBox->Items->Add(storageList[i]);
  34. }
  35. }
  36.  
  37. if(toolStripComboBox->Items->Count > 0)
  38. {
  39. String ^ sText = toolStripComboBox->Items[0]->ToString();
  40. toolStripComboBox->SelectionStart = searchText->Length;
  41. toolStripComboBox->SelectionLength = sText->Length - searchText->Length;
  42.  
  43. }
  44. else
  45. {
  46. toolStripComboBox->DroppedDown = false;
  47. toolStripComboBox->SelectionStart = searchText->Length;
  48. }
  49. }
  50. else
  51. {
  52. toolStripComboBox->DroppedDown = false;
  53. toolStripComboBox->Items->Clear();
  54. }
  55. }
  56.  
  57. toolStripComboBox_TextUpdate
  58. toolStripComboBox_KeyDown
  59. toolStripComboBox_DropDown
  60. toolStripComboBox_ChangeCommit
  61.  
  62. toolStripComboBox_TextUpdate(System::Object^ sender, System::EventArgs^ e) {
  63. String ^ searchText = toolStripComboBox->Text;
  64. toolStripComboBox->Items->Clear();
  65.  
  66. if(searchText != "") {
  67. Regex ^ searchRegex = gcnew Regex("(?i).*"+searchText+".*");
  68.  
  69. for(int i = 0; i<storageList->Count; i++) {
  70. Match ^ m = searchRegex->Match(storageList[i]);
  71. if(m->Value == storageList[i]) {
  72. toolStripComboBox->Items->Add(storageList[i]);
  73. }
  74. }
  75.  
  76. if(toolStripComboBox->Items->Count > 0) {
  77. toolStripComboBox->DroppedDown = true;
  78. toolStripComboBox->Text = searchText;
  79. Cursor->Current = Cursors::Default;
  80. }
  81. else {
  82. toolStripComboBox->DroppedDown = false;
  83. }
  84. toolStripComboBox->SelectionStart = searchText->Length;
  85. }
  86. else {
  87. toolStripComboBox->DroppedDown = false;
  88. toolStripComboBox->Items->Clear();
  89. }
  90. }
  91.  
  92. toolStripComboBox_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e) {
  93. String ^ searchText = toolStripComboBox->Text;
  94. if(e->KeyCode == Keys::Down || e->KeyCode == Keys::Up) {
  95. if(e->KeyCode == Keys::Down) {
  96. if(toolStripComboBox->SelectedIndex == -1 && toolStripComboBox->Items->Count > 0) {
  97. toolStripComboBox->SelectedIndex = 0;
  98. }
  99. }
  100. if(e->KeyCode == Keys::Up) {
  101. if(toolStripComboBox->SelectedIndex == -1 && toolStripComboBox->Items->Count > 0) {
  102. toolStripComboBox->SelectedIndex = toolStripComboBox->Items->Count - 1;
  103. }
  104. }
  105. keydownTxt->Text = Convert::ToString(toolStripComboBox->SelectedIndex);
  106. }
  107. if(e->KeyCode == Keys::Back) {
  108. toolStripComboBox->SelectionStart = searchText->Length;
  109. }
  110. if(e->KeyCode == Keys::Enter) {
  111. toolStripComboBox_ChangeCommit(sender, e);
  112. }
  113. }
  114.  
  115. toolStripComboBox_DropDown(System::Object^ sender, System::EventArgs^ e) {
  116. String ^ searchText = toolStripComboBox->Text;
  117. toolStripComboBox->SelectionStart = searchText->Length;
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement