none
PROBLEM - Linq to SQL with Windows Forms ComboBox RRS feed

  • Question

  • Hello,
    I have the following piece of code that works

                PhoenixDataContext dc = new PhoenixDataContext();  
     
                var searchQType = (from q in dc.GetTable<Question>()  
                                   where q.Question_Type.QuestionType == "True or False"  
                                   select q);  
     
                var display = searchQType.ToList();  
                dataGridView1.DataSource = display


    I want to extend the code to incorporate the use of a combobox instead of having to specify the search criteria in the code.
    I have changed the code to this:

                PhoenixDataContext dc = new PhoenixDataContext();  
     
                var searchQType = (from q in dc.GetTable<Question>()  
                                   where q.Question_Type.QuestionType.Equals(ComboBoxQuestionType.SelectedText)  
                                   select q);  
     
                var display = searchQType.ToList();  
                dataGridView1.DataSource = display


    The QuestionType table is bound to a combobox which lists all of the available question types. However when you select the question type from the list the datagridview does not display any data, it just displays the table column headings on their own.
    I cannot understand why the code does not work.
    Any help would be greatly appreciated.
    Kinds regards, Simon

    Wednesday, January 7, 2009 11:42 PM

All replies

  • I think you have to use the ComboBox.SelectedValue or ComboBox.Text property instead. I think the SelectedText property will only return the text that is highlighted
    • Proposed as answer by Mike Ceranski Sunday, January 18, 2009 1:54 AM
    Sunday, January 18, 2009 1:54 AM
  • Use SelectedItem instead of SelectedText it will work.


    Ovais Mehboob

    Sunday, April 8, 2012 9:50 AM