/* Firstly... * We have an IF function that checks whether "names" contains the content of the search box, so if its a letter "a", it checks if its in our list. * It then creates a variable "SearchText" that we can later use that simply means that instead of writing the whole code we can just refer to it by our new name * Another variable! This one defines our Index in our list, it takes our previous variable and looks for it in our list and finds what the index number of that value is. * Now, since its Search on demand we essentially have two Lists (arrays) now that we have the name of the value we looking for in string format, we also have our index as integer (defined earlier in class). We need to take that data and add it to our display List and for that we have our function. Adds new Items to our list using the Items Class and also defines what data should be put into each column. * It then clears the search text box * and shows us that the value has been found. We then move to ELSE which is simple really... * Didn't find data * Clears search text box * Displays message that its not been found... */ private void Search_Button_Click(object sender, RoutedEventArgs e) { if (names.Contains(Search_Text.Text)) // Our If statement { var SearchText = Search_Text.Text; // First Variable var FindIndex = names.IndexOf(SearchText); // Second Variable List_Box.Items.Add(new Items() { Index = FindIndex, Name = SearchText}); // Adding items to display list Search_Text.Clear(); // Clear search text box MessageBox.Show("Data Found"); // Display message } else { Search_Text.Clear(); MessageBox.Show("Not Found"); }; }
private void SearchForm()//マスタ 入力 { if (String.IsNullOrEmpty(Search_Box.Text.TrimEnd()) || Search_Box.Text.TrimEnd() == Search_Text.TrimEnd()) { return; } ButtonText(panel_right, dtMenu, 3); var dr = dtMenu.Select(" ProgramID like '%" + Search_Box.Text.TrimEnd() + "%'"); if (dr.Count() > 0) { var dtsend = dr.CopyToDataTable(); dtsend.DefaultView.Sort = "BusinessID ASC,BusinessSEQ ASC,ProgramID ASC"; dtsend.Columns.Add("Index", typeof(string)); int g = 0; foreach (DataRow dro in dtsend.Rows) { g++; dro["Index"] = g.ToString(); } dtSearch = dtsend; ButtonText(panel_right, dtsend, 2); } else { dtSearch = null; string Cap = "Menus you are searching were not found. " + Environment.NewLine + "Please,Try with another keywords again."; MessageBox.Show(Cap, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } }
private void SearchTextBox_Focus() { Search_Text.Text = ""; Search_Text.Focus(); }