I have an ultragrid on a Windows form. The grid is added at runtime (there can be up to 6 grids added to the form depending on values found in the data).
An ultracomboeditor control which is also added in code is bound to a column called 'Value' .
There may be one or more rows were the drop down list for a cell is filled with 'Staff names' If the name entered by the user is not in the drop down list an error is trapped, a msgbox is then presented and if the user responds 'Yes', a Dialogue is shown that allows the users to enter the new persons name in a 'Quick Add function'. However there are some issues that I need some help with please such as:
a) How do i refresh the Value list for the 'Value' column in the specific cell that they user is currently into include the new person?
b) How do i refresh the Value list for the 'Value' column for any other rows in the grid where the user needs to see the name of the person that was entered into the person table?
If I press the 'ESc' key twice in the first row I can get the value list to refresh when the user has entered a value for the first row but I want to do this in code and Ialso want to refresh the value list for other rowsas described below.
For example there may be two rows in the grid, one is labelled ' Enter the name of person attending session one' and another row, 'Enter the name of person attending session two'.
If the user enters a name in the 1st row that does not exist, and the dialogue is presnetred and the user enters a name how to refresh the value list for that cell and reset the selected value and how do i refresh the Value list for the 'Value' column for any other rows in the grid where the user needs to see the name of the person that was entered into the person table after the grid vaue lists were populate. Cell value lists get populated at initialisation of the row
Thank you for your help
Hi,
I'm having a hard time answering your questions here because there are quite a few unknowns.
First... how ar eyou assigning the UltraComboEditor to the cells?
Are you assigning it to the column or to individual cells?
Are you setting the EditorControl property on the column/cell? Or are you using the ValueList property?
Why are you using an UltraComboEditor to provide a drodown list in a grid cell? While this is certainly possible, it's actually not very efficient. You would be much better off using a ValueList. See this article: HOWTO:What is the best way to place a DropDown list in a grid cell?
How are you populating the list? Are you binding the UltraComboEditor? Or are you populating it manually?
Are the lists in the first and second column the same?
Hi Mike
Thnak you for your reply
/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;}
To answer your questions - Iam assigning the UltraComboEditor to the cells in the BeforeRowActivate by calling
Private Sub GetValueList(ByVal oUltragridRow As UltraGridRow) Const scRoutine As String = "frmClinicalAudit. GetValueList" Dim sFindingkey As String = Nothing Dim theSettings As New DefaultEditorOwnerSettings Dim theOwner As New DefaultEditorOwner(theSettings) Dim theEditor As EmbeddableEditorBase = Nothing Dim sFindingValueKey As String = Nothing Dim sFindingValueDesc As String = Nothing Dim sValueKey As String = Nothing Dim sValueDesc As String = Nothing Dim oDataReader As SqlClient.SqlDataReader = Nothing Dim sSQL As String = Nothing Dim uce As UltraComboEditor = New UltraComboEditor Try Call goErr.Log("start " + scRoutine)
uce.Name = "oUltraComboEditor" uce.DropDownListWidth = -1 ' fit the widest text sSQL = oUltragridRow.Cells("SQLToGetValues").Text If Len(Trim(sSQL)) <> 0 Then sFindingValueKey = Trim(oUltragridRow.Cells("ValueListValueColumn").Text) sFindingValueDesc = Trim(oUltragridRow.Cells("ValueListDisplayColumn").Text) oDataReader = goLassoDB.GetDataReader(sSQL, True) Do While oDataReader.Read() = True sValueKey = Trim(goLassoDB.GetString(oDataReader, sFindingValueKey)) sValueDesc = Trim(goLassoDB.GetString(oDataReader, sFindingValueDesc)) uce.Items.Add(sValueKey, sValueDesc) Loop oUltragridRow.Cells("Value").EditorControl = uce oUltragridRow.Cells("Value").Style = ColumnStyle.DropDownValidate 'close the SQL reader oDataReader.Close() End If Catch 'close the SQL reader oDataReader.Close() Call goErr.HandleRoutineError(scRoutine) End Try End Sub
I think that it is mostly workign now except for two issues
a) The amount of time i spen 'researchign the use of the LimitToList property you probably wouldn't believe ONLY toi fianlly find that as as Editor this is useless and I needed to set oUltragridRow.Cells("Value").Style = ColumnStyle.DropDownValidate for the equivalent of the LimitToList feature to work
b) Perhaps most importantly I have handled the error from the DropDownValidate event as per the following
Private Sub oUltraGrid3_Error(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.ErrorEventArgs) Handles oUltraGrid3.Error Const scRoutine As String = "frmClinicalAudit.oUltraGrid3_Error" Dim Response As MsgBoxResult Try If e.DataErrorInfo.Row.Cells("AllowQuickAdd").Text = "True" Then Response = (MsgBox("The Value that you entered for '" + e.DataErrorInfo.Row.Cells("Finding").Text + "' Was not found - Do you want to add that value to the list?", MsgBoxStyle.YesNo, "The value entered for:" + e.DataErrorInfo.Row.Cells("Finding").Text + " was not found")) If Response = MsgBoxResult.Yes Then Call QuickCareProviderAdd() Call GetValueList(e.DataErrorInfo.Row) End If
e.Cancel = True End If oUltraGrid3.DisplayLayout.Bands(0).Columns(e.DataErrorInfo.Cell.Column.Index).InvalidValueBehavior = InvalidValueBehavior.RetainValueAndFocus Catch ex As Exception Call goErr.HandleRoutineError(scRoutine) End Try
Now here is the very interesting part unless I pressed the 'Escape' key the applciation would get an unhandled exception error after updaing the drop[ down lists via calling Call GetValueList(e.DataErrorInfo.Row) from oUltraGrid3_Error However Now I have added
Private Sub oUltraGrid3_CellDataError(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.CellDataErrorEventArgs) Handles oUltraGrid3.CellDataError Const scRoutine As String = "frmClinicalAudit.oUltraGrid3_CellDataError" Try Call goErr.Log("start " + scRoutine) e.StayInEditMode = False Catch ex As Exception Call goErr.HandleRoutineError(scRoutine) End Try End Sub
AND now the app no longer issues the unhandled exception error. It seems that the e.StayInEditMode = False was the key
However, while it is working almost as I'd like it to now (except that the user cursor is not in the column that I'd like it to be) it that seems odd to me that toggling the e.StayInEditMode = False avoids an unhandled exception error that seem to be coming from the Ultragrid components
Also it is my 10 cents worth that there is a VERY real need for some documentation on the differences between the use of the controls as typicaly Windows forms controls and as WinGrid Editors (e.g LimitToList not applicable use ColumnStyle.DropDownValidate instead would have saved me about oh 3 hours (or more) of 'trial and error')
Thanks for your help and feedback