ShowDropDown problem

2 posts, 1 answers
  1. Jeff Clark
    Jeff Clark avatar
    15 posts
    Member since:
    Feb 2010

    Posted 26 Jul 2011 Link to this post

    I am using a RadDropDownList (Q2 2011) as a search box to find a student. The user types in a name into the RadDropDownList and either hits the enter key or clicks a button.

    I am using the KeyPress event to test for the enter key.  Both the KeyPress event and the button click event call a FindStudent routine.

    The FindStudent routine retrieves data from a database and populates the RadDropDownList using a for loop and adding an object to the list with .Items.Add method. At the end of the routine it calls the ShowDropDown() method.

    If I type in the RadDropDownList and click on the button, the drop down shows correctly.  If I type in the RadDropDownList and hit the Enter key the drop down shows and then immediately disappears.

    How can I get the drop down to stay when hitting the enter key?  Thanks for your help.

    Below is my code for the KeyPress event, Button Click event and FindStudent routine.
    private void FindStudent_Btn_Click(object sender, EventArgs e)
    {
        string fsText = FindStudent_DDL.Text;
        FindStudent_DDL.Items.Clear();
        FindStudent(fsText);
    }

    private void FindStudent_DDL_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (e.KeyChar == (char)13)
        {
            string fsText = FindStudent_DDL.Text;
            FindStudent_DDL.Items.Clear();
            FindStudent(fsText);
        }
    }

    private void FindStudent(string fsText)
    {
        ... code that retrieves data from database and populates a DataTable dt ...
         
        if (dt.Rows.Count > 0)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                StudentObject student = new StudentObject(dt.Rows[i]["id_num"].ToString(), dt.Rows[i]["last_name"].ToString(), dt.Rows[i]["first_name"].ToString());
                FindStudent_DDL.Items.Add(new RadListDataItem(student.ToString(), student));
            }
        }
     
        FindStudent_DDL.ShowDropDown();
    }
  2. Answer
    Jeff Clark
    Jeff Clark avatar
    15 posts
    Member since:
    Feb 2010

    Posted 27 Jul 2011 Link to this post

    I solved the problem. In my initial testing I had previously set the AutoCompleteMode property to suggest and that was causing the disappearance of the Dropdown.
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top