Click here to Skip to main content
15,901,853 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
XAML
<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>

C#
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);
    }
}


What I have tried:

C#
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);
    }
}
Posted
Updated 24-Feb-23 2:16am
v2
Comments
Richard Deeming 24-Feb-23 8:17am    
Beyond that, you've forgotten to ask a question. You've just dumped a load of unexplained code on us, and said it's "not working". We have no idea what it's supposed to do, what it's actually doing, what you have tried, or where you are stuck.
Graeme_Grant 24-Feb-23 17:55pm    
You would think that after posting 35 questions, they would know better! If they are not going to try, why should we?
prashanth manoj 25-Feb-23 5:30am    
after filter database values select using down arrow keys in drop down that is what my issue
Richard Deeming 27-Feb-23 4:06am    
That may be your issue now; but once you've let your users loose on your application, your issue will very quickly become "why has the data disappeared and/or been corrupted?", and "where am I going to find millions of dollars to pay these massive fines I've been hit with for not securing my database properly?"

The way you've written your code leaves it vulnerable to deliberate or accidental SQL Injection. Your data is not going to survive that.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900