<ComboBox IsEditable="True" IsTextSearchEnabled="False" PreviewTextInput="txtSearch_PreviewTextInput" TextBoxBase.TextChanged="TxtSearch_TextChanged" x:Name="txtSearch" Text="{Binding txtSearch}" Background="White" FontSize="30" Margin="0,66,0,0" KeyDown="txtSearch_KeyDown" ScrollViewer.VerticalScrollBarVisibility="Auto" SelectionChanged="txtSearch_SelectionChanged" PreviewKeyDown="txtSearch_PreviewKeyDown"> <ComboBox.ItemsPanel> <ItemsPanelTemplate> <VirtualizingStackPanel TextSearch.TextPath="foodname"/> </ItemsPanelTemplate> </ComboBox.ItemsPanel> </ComboBox>
private void TxtSearch_TextChanged(object sender, TextChangedEventArgs e) { try { if (txtSearch.Text != null && txtSearch.Text.Length > 0) { txtSearch.ItemsSource = null; s_table = "2"; DataSet ds = Globalvariables.Globals.select_load("Select menu_id,foodname,rprice from add_food_menu where foodname like '%" + txtSearch.Text + "%'"); if (ds != null && ds.Tables[0].Rows.Count > 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { string id = ds.Tables[0].Rows[i][0].ToString(); string name = ds.Tables[0].Rows[i][1].ToString(); string qty = "1"; string price = ds.Tables[0].Rows[i][2].ToString(); string total = price; txtSearch.DisplayMemberPath = "foodname"; txtSearch.SelectedValuePath = "menu_id"; txtSearch.ItemsSource = ds.Tables[0].DefaultView; txtSearch.SelectedIndex = -1; } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void txtSearch_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { s_table = ""; ComboBoxItem item = txtSearch.SelectedItem as ComboBoxItem; if (item != null) { MessageBox.Show("Selected item: " + item.Content, Title); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)