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
240
Change UltraCombo datasource
posted

I have a project where I need to requery the datatable that an ultracombo uses for its datasource.  When the datatable is requeried the columns change also, don't know if this makes a difference or not. After the datatable is requeried the form is pretty much dead (except for the ultracombo control).  I can click on the other controls I have on the form and nothing happens.  The code I use to do the requery follows:

 

 private void LoadSearchCombo(string f1, string where)

        {

            if (f1 == "Last Name")

            {

                sql = "SELECT RecordID,LastName,FirstName,StudentID FROM StudentData " + where + " ORDER BY LastName,FirstName ";

            }

            else if (f1 == "StudentID")

            {

                sql = "SELECT RecordID,StudentID,LastName,FirstName FROM StudentData " + where + " ORDER BY LastName,FirstName ";

            }

            else if (f1 == "Barcode")

            {

                sql = "SELECT RecordID,Barcode,LastName,FirstName,StudentID FROM StudentData " + where + " ORDER BY LastName,FirstName ";

            }

            dbCmd.CommandText = sql;

            dbCmd.Connection = dbConn;

            dbAdp = new OleDbDataAdapter(sql, dbConn);                   

 

            if (dtSearch != null)

            {                

                dtSearch.Dispose();

            }

 

            dtSearch = new DataTable();

            dbAdp.Fill(dtSearch);            

            if (!bstartup)

            {

                ucSearch.DataSource = null;

                ucSearch.Refresh();

                ucSearch.DataBind();

            }

            if (f1 == "Last Name")

            {

                ucSearch.DisplayMember = "LastName";

            }

            else

            {

                ucSearch.DisplayMember = f1;

            }

            ucSearch.ValueMember = "RecordID";

            ucSearch.DataSource = dtSearch;

            ucSearch.DataBind();

            ucSearch.Refresh();                                         

            foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in ucSearch.Rows)

            {

                ucSearch.SelectedRow = row;

                break;

            }

 

        }

 

I have tried numerous combinations of DataBind() and Refresh(), but none have worked so far.

Any help would be appreciated.

 

Thanks,

 

 

  • 469350
    Suggested Answer
    Offline posted

    Hi,

    DataBind is pretty much redundant in WinForms. Setting the DataSource property does an implicit bind, so you should not call DataBind, as it will just call the same code twice. Refresh is also unneccessary.

    I don't know why every other control on the form would become unresponsive or the how the co0mb could possibly cause that. But the code you have here that loops through every row in the combo and selects it is quite puzzling. Why are you doing that? This seems like a terribly inefficient and pointless thing to do. Especially since you are breaking out after the first iteration.