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
195
UltraComboEditor Datasource problem
posted

So I am adding a UltraComboEditor to a UltraGrid on the fly as the editor control for a cell. I do this in the after row insert event.

When I set the datasource (an UltraDataSource) of the UltraComboEditor I don't see the items on the UI. It looks as though there is no datasource at all. The datasource is fine as it works if I use the UltraCombo control instead.

What extra step do I need to perform with the UltraComboEditor to get it to show the items from the datasource?

This is the relevent code:

/// <summary>

/// Row Inserted

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void RequestGrid_AfterRowInsert(object sender, RowEventArgs e) {

    // account mappings only past this point

    if(e.Row.Band.Index != 1) {

        return;

    }         

    // get the account number

    string accountNumber = e.Row.ParentRow.Cells["AccountNumber"].Value.ToString();

    // jig up an account

    Account A = new Account(accountNumber);

    // get instances

    ChartDataCache DataCache = ChartDataCache.Instance;

    // get rowsets

    DataRow[] Rowsets = DataCache.AccountDetailData.Tables["Rowsets"].Select("CompanyNumber = '" + A.CompanyNumber + "'");

    // rowset edit control          

    UltraComboEditor RowsetComboEditor = new UltraComboEditor();          

    RowsetComboEditor.Name = Guid.NewGuid().ToString();

    RowsetComboEditor.Visible = false;            

    // set datasource

    RowsetComboEditor.DisplayMember = "RowsetName";

    RowsetComboEditor.ValueMember = "RowsetName";

    // bind

    BindToRows(RowsetComboEditor, Rowsets, "(Select)", "(Select)", "(None Available)");        

    // add it to the grid and set it as the edit control

    RequestGrid.Controls.Add(RowsetComboEditor);                       

    e.Row.Cells["RowsetName"].EditorControl = RowsetComboEditor;                       

}

/// <summary>

/// Bind a menu to a list of data rows

/// </summary>

/// <param name="Menu"></param>

/// <param name="Rows"></param>

private void BindToRows(UltraComboEditor Menu, DataRow[] Rows, string initialText, string initialValue, string emptyVal) {

    try {

        // flag an empty set

        bool emptySet = Rows.Length == 0;

        // anything there?

        if(emptySet) {

            // create data to represent an empty set

            DataTable T = new DataTable("Empty");

            T.Columns.Add(Menu.DisplayMember, typeof(string));

            T.Columns.Add(Menu.ValueMember, typeof(string));

            T.Rows.Add("(None Available)", emptyVal);

            Rows = T.Select();

        }

        // data source instance

        UltraDataSource S = new UltraDataSource();

        // add columns

        foreach(DataColumn C in Rows[0].Table.Columns) {

            S.Rows.Band.Columns.Add(C.ColumnName);

        }

        if(!emptySet) {

            if(Rows.Length > 1) {

                DataRow SelectRow = Rows[0].Table.NewRow();

                SelectRow[Menu.DisplayMember] = initialText;

                SelectRow[Menu.ValueMember] = initialValue;

                S.Rows.Add(SelectRow.ItemArray);

            }

        }

        // add data

        foreach(DataRow R in Rows) {

            S.Rows.Add(R.ItemArray);

        }

        // set data source

        Menu.DataSource = S;

    }

    catch(Exception ex) {

       

    }

}

 

Parents
  • 469350
    Offline posted

    My guess is that the UltraComboEditor has no BindingContext. I recommend that you add the control to form's Controls collection. This will allow the control to get the BindingContext from the form. It will also ensure that the control gets disposed when the form is disposed. The way you have it set up now, your form will have a memory leak since the control will never get disposed.

     

Reply Children