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.
Hello Ethan,
Thank you for contacting Infragistics. I don't see anywhere where you are adding this new instance of CurrentLayoutControl to the form. Normally when you instantiate a control you have to add it to the this.Controls collection and then give it a size/location etc.
I see you posted here:
https://stackoverflow.com/questions/76263639/infragistics-ultracombo-will-not-populate-data-although-data-is-being-retrieved
But we'll need a sample to further investigate this. I attached a working example. Please modify it if you still have any issues.
5706.WindowsFormsApp5.zip