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) {
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.
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
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.
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.
I am setting a DataSource which is an array of System.Data.DataRow objects. When I specify the DataMember, the DataBind method does not bind any data and Items.Count is equal to zero. However, if DataMember is Nothing then the list is bound to all the items in the array. To get around this, the first property of the DataRow object is the DataMember I want to specify. Is this a bug?
Hi Phil,
I'm not sure what you are trying to do here. DataMember has no meaning for an Array. DataMember specifies which list to use when you bind to a data source that has multiple lists, such as a DataSet. If you are binding to an Array, then any DataMember you specify will not exist, since there is only one list, and it makes no sense to set this property.
Oh, oops. My misunderstanding of what DataMember was trying to do. I thought it specified the property to use as the DisplayText of the object within the array.
So, if I had an array of objects that had the properties: DisplayName, Value and Key. Then DataMember would be set to DisplayName to DataMember to indicate that I wanted the DisplayName property to be bound to the DisplayText property of the ValueListItem.
Sorry.
Okay, I see what happened. You are mixing up DataMember with DisplayMember. What you want to do here is set DisplayMember to the DisplayName. And probably ValueMember to the Key (or Value).