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;
/// Bind a menu to a list of data rows
/// <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) {
If it's not th BindingContext, then I'm afraid I am at a loss. If you want to track this down, I recommend creating a small sample project demonstrating the issue and then you can Submit an incident to Infragistics Developer Support.
If they can see the problem occur, they should be able to tell you why it's happening.
The control is on a panel. So "this" is a panel, not the actual form. In any case wheather I do this.BindingContext, or this.ParentForm.BindingContext the result is the same.
What I don't get is why it works with a UltraCombo, but not an UltraComboEditor?? Is there a known issue with this control?? I'll just use the UltraCombo and deal with the extra setup.
Thanks.
Are you adding the control to the form before you set it's DataSource?
The only other thing I can think of is maybe you need to set the BindingContext explicitly. After you add the control to the form, try something like this:
ultraComboEditor1.BindingContext = this.BindingContext;
I'm assuming that this is the form.
Thanks for the tip on adding the control to the form's control collection. Unfortunately, the problem of the list items not being displayed still exists.
I'm using NetAdvantage for .NET 2007 Vol. 2 CLR 2.0
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.