I need to edit a cell and when it enters edit mode, I need it to show a dropdown with values that come from a DB.
I can create the dropdown, and it populates, and the dropdown even shows in the cell. But when I click on the dropdown, nothing happens.
I don't know if it's that the cell's not expanding to show me the values, or if the values are somehow not making it to the cell.
private void ROGridServerDBs_AfterEnterEditMode(object sender, EventArgs e) { UltraDropDown drop = new UltraDropDown(); string column = new GridInfo().GetActiveCellName(ROGridServerDBs); if (column == "ServerRole") { string query = new MEQueries().AppRolesGet(); UltraGridCell activeCell = ROGridServerDBs.ActiveCell; MinionConn mc = new MinionConn(); drop.DataSource = mc.RunQuery(query); drop.ValueMember = "AppRoleName"; drop.DisplayMember = "AppRoleName"; activeCell.ValueList = drop; activeCell.Refresh(); } }
private void ultraGrid1_CellChange(object sender, CellEventArgs e) { if(e.Cell.Column.Key == "DropDown") { int dropdown_row_index = (e.Cell.Column.ValueList as UltraDropDown).ActiveRow.Index; var item = ultraDropDown1.Rows[dropdown_row_index]; e.Cell.Row.Cells["Column"].Value = item.Cells["CustomerID"].Text;; } }
That worked beautifully. I see what I did wrong. There's just one more thing... I need to set another col value based on the value chosen in the dropdown. So the dropdown has multiple cols and I need the other col in my table to be changed to the value from that same row.
In other words, I have col1 and col2 in the table. When I choose another value from the dropdown in col1, I want col2 to be updated with the value in col2 from the dropdown. Did I say that right?
Hello Sean,
I assume that by "regular cell" you mean cell that already exists in your underlying data source. I modified the previously provided sample and created a simple flat data source with two columns. While populating the data, I am setting some values for the purpose of the example. In case that this column cells do not have initial values they can be populated later from the drop down provider. After the grid is bound, the only difference from the previous sample is that there is no unbound column but an existing column which value list is set to the UltraDropDown. If this is not an accurate demonstration of what you are trying to achieve please feel free to modify it and send it back to me along with steps to reproduce. Alternatively, if the behavior cannot be replicated please feel free to provide your own sample. Remove any external dependencies and code that is not directly related to the issue, zip your application and attach in in this case.Having a working sample on my side, which I can debug, is going to be very helpful in finding the root cause of this behavior.I have attached the modified application here.
Let me know if I may be of any further assistance.
Sincerely,Teodosia HristodorovaAssociate Software Developer
Thanks for that. Your app adds a new col. What I need is to take a regular cell, and turn it into a dropdown when in edit mode. So far I haven't had much luck with it.
Hello Sean,Thank you for the code-snippet you have provided.
What I noticed is that you are creating and assigning the UltraDropDown control inside of AfterEnterEditMode. However, once the cell has entered edit mode, it's using a default text editor instead of the UltrDropDown and this is the reason why it can not be opened.
My suggestion to achieve your requirement is to assign the UltraDropDown to the cell in InitializeLayout event. This will ensure that the drop down will be assigned to the cell before it enters edit mode.
private void ultraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e) { this.ultraGrid1.DisplayLayout.Bands[0].Columns.Add("DropDownColumn", "DropDown Column"); e.Layout.Bands[0].Columns["DropDownColumn"].ValueList = ultraDropDown1; }
Afterwards, AfterEnterEditMode event can be handled to drop it down.
private void ultraGrid1_AfterEnterEditMode(object sender, EventArgs e) { var grid = (UltraGrid)sender; grid.BeginInvoke(new MethodInvoker(this.DropDownGridCellListIfNeeded)); } private void DropDownGridCellListIfNeeded() { var grid = this.ultraGrid1; var activeCell = grid.ActiveCell; if (null == activeCell || activeCell.DroppedDown) return; var editor = activeCell.EditorResolved as EditorWithCombo; if (null == editor) return; activeCell.DroppedDown = true; }
Sample application, that uses the approach from above can be found here.If you require any further assistance on the matter, please let me know.