Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
20
UltraCombo will not populate from db query
posted

I have a custom combo box class that inherits UltraCombo. I need it to display data from a database query. I have verified that the data is in fact being retrieved (i.e. I can print the query results on the console from the method that is supposed to populate the form). No matter what I do, the control does not display the data. The control is part of the Controls collection, as it is visible when running the app. Everything I have seems to comply with the documentation, but it just doesn't work.

Here is my code: 

Main form class:

public partial class SaveLayoutTestForm : Form
{
    public CurrentLayoutControl currentLayoutControl;

    public SaveLayoutTestForm()
    {
        this.currentLayoutControl = new CurrentLayoutControl();
        PopulateLayoutCombo();
    }

    public void PopulateLayoutCombo()
    {
        DataTable layouts = currentLayoutControl.LoadUserGridLayouts(connectionString);
        currentLayoutControl.DataSource = layouts;
        currentLayoutControl.ValueMember = "User_Grid_Layout_Id";
        currentLayoutControl.DisplayMember = "User_Grid_Layout";
    }
}

CurrentLayoutControl class:

public class CurrentLayoutControl : UltraCombo
{
    public DataTable LoadUserGridLayouts(string connString)
    {
        DataTable dataTable = new DataTable();
        SqlConnection conn = new SqlConnection(connString);
        string sql = "USE my_database; SELECT User_Grid_Layout_Id, User_Grid_Layout FROM app.User_Grid_Layouts";
        SqlCommand command = new SqlCommand(sql, conn);

        conn.Open();
        dataTable = ExecuteQuery(connString, command);
        conn.Close();
        return dataTable;
    }

    private DataTable ExecuteQuery(string connString, SqlCommand command)
    {
        DataTable dataTable = new DataTable();
        SqlDataAdapter adapter = new SqlDataAdapter(command);
        adapter.Fill(dataTable);
        return dataTable;

    }
}

Thank you for any help, I really appreciate it.

Parents
No Data
Reply Children
No Data