Hi,
I have a grid where I want a column to be a drop down that the user can both select from or type into. When the user types into it then tabs out if the text is not in the list it will open up another form that the user can do a search with in order to add the item to the list. I tried a value list at first but there was no Not in List event so I am trying to use the UltraComboEditor, which I want to look like a normal drop down but have not yet got that far.
I have a project (I tried to include it but it would not let me post a 5.9kb file) where I have an ultragrid on the form, a table is create and bound to the grid in code which is working, then I try to set a columns editor component to an UltraComboEditor but nothing shows in the drop down list, there are items in the table that I am using for the UltraComboEditor so I think they should show in the editor drop down.
My questions are therefore:
1. Why is nothing showing in the drop down
2. How do I get NotInList event to fire?
Thanks
Paul
Code is here, it is just a wondows form project with an ultragrid dropped on the form, nothing changed in the ultragrid from standard
DataTable gridTable; public Form1() { InitializeComponent(); CreateTableAndBindToGrid(); SetEntityIDToUltraCombo(); } private void CreateTableAndBindToGrid() { gridTable = new DataTable(); gridTable.Columns.Add("EntityID", typeof(int)); gridTable.Columns.Add("Description", typeof(String)); this.gridTable.Rows.Add(new object[] { 1, "Paul" } ); this.gridTable.Rows.Add(new object[] { 2, "John" }); this.gridTable.Rows.Add(new object[] { 3, "Heidi" }); this.ultraGrid1.SetDataBinding(this.gridTable, "", true); } private void SetEntityIDToUltraCombo() { this.ultraGrid1.DisplayLayout.Bands[0].Columns["EntityID"].EditorComponent = GetUltraComboEditor(); } private UltraComboEditor GetUltraComboEditor() { DataTable comboTable = new DataTable(); comboTable.Columns.Add("ID", typeof(int)); comboTable.Columns.Add("EntityName", typeof(String)); comboTable.Rows.Add(new object[] { 1, "Paul" }); comboTable.Rows.Add(new object[] { 2, "John" }); comboTable.Rows.Add(new object[] { 3, "Heidi" }); UltraComboEditor editor = new UltraComboEditor(); editor.DataSource = comboTable; editor.ValueMember = "ID"; editor.DisplayMember = "EntityName"; editor.DropDownStyle = Infragistics.Win.DropDownStyle.DropDown; editor.ItemNotInList += Editor_ItemNotInList; return editor; } private void Editor_ItemNotInList(object sender, ValidationErrorEventArgs e) { throw new NotImplementedException(); }
Edited: I have since dicsovered the UltraComboEditor has to be added to the forms control collection so I did that (albeit not in the code above) and can see the drop down, still cannot got anything for Not In List though.
Hi Andrew,
Thanks this is what I am looking for. I have added code in the grid error handler that adds a new item to the combo editors bound table and then selects that items ID as the value for the cell which is the behavior I was looking for.
BindingContext has resolved the first issue without having to add controls to the forms control collection which is great too.
Thanks for your help,
Hello Paul,
Thank you for your post. I have put together a sample project to try to reproduce the behaviors you are seeing, and I have. I will answer your inquiries in the order they were asked.
1. I see that you were able to resolve this piece, but this was likely due to a missing BindingContext. If you set the following in your code, it should resolve itself, where ‘editor’ is the UltraComboEditor:
editor.BindingContext = this.BindingContext;
2. The NotInList event will not fire in this case. When the editor is embedded in the UltraGrid, it essentially isn’t actually used to update the underlying value of the cell. The UltraComboEditor is essentially providing a copy of its editor to the grid to be used with the cell and so the value validation happens on the grid and not the UltraComboEditor. I would recommend handling the Error event on the UltraGrid for an event that fires in this case. You also may need to set the LimitToList property on your UltraComboEditor to true.
I am attaching the sample project I created based on your code to demonstrate the above. I hope this helps you.
Please let me know if you have any other questions or concerns on this matter.
UltraComboEditorNoItemsTest.zip