I need to programmatically create editor providers. Is that possible? I will be creating dropdown, datepicker, numeric and percent providers. If possible, can you provide some example code in VB? Thanks!
Hello kpjgpm ,
Please refer to the documentation regarding editor providers in WebDataGrid
You may use the same approach in the WHDG too:
http://help.infragistics.com/NetAdvantage/ASPNET/2010.3?page=WebDataGrid_Using_Editor_Providers.html
For example :
In Visual Basic:
' Enable cell editing Me.WebDataGrid1.Behaviors.CreateBehavior(Of EditingCore)() Me.WebDataGrid1.Behaviors.EditingCore.Behaviors.CreateBehavior(Of CellEditing)() ' Create an editor provider Dim datePickerProvider As New DatePickerProvider() datePickerProvider.ID = "DatePickerProvider1" ' Add to collection Me.WebDataGrid1.EditorProviders.Add(datePickerProvider) ' Create a column setting to use the editor provider Dim columnSetting As New EditingColumnSetting() columnSetting.ColumnKey = "RequiredDate" ' Assign editor for column to use columnSetting.EditorID = datePickerProvider.ID ' Add column setting Me.WebDataGrid1.Behaviors.EditingCore.Behaviors.CellEditing.ColumnSettings.Add(columnSetting) Let me know if you need further assistance
' Enable cell editing Me.WebDataGrid1.Behaviors.CreateBehavior(Of EditingCore)() Me.WebDataGrid1.Behaviors.EditingCore.Behaviors.CreateBehavior(Of CellEditing)() ' Create an editor provider Dim datePickerProvider As New DatePickerProvider() datePickerProvider.ID = "DatePickerProvider1" ' Add to collection Me.WebDataGrid1.EditorProviders.Add(datePickerProvider) ' Create a column setting to use the editor provider Dim columnSetting As New EditingColumnSetting() columnSetting.ColumnKey = "RequiredDate" ' Assign editor for column to use columnSetting.EditorID = datePickerProvider.ID ' Add column setting Me.WebDataGrid1.Behaviors.EditingCore.Behaviors.CellEditing.ColumnSettings.Add(columnSetting)
' Enable cell editing
Me
Of
' Create an editor provider
Dim
As
New
"DatePickerProvider1"
' Add to collection
' Create a column setting to use the editor provider
"RequiredDate"
' Assign editor for column to use
' Add column setting
I can't get the dropdown provider to work. Here is my code that creates the columns in the grid. I have a table in the DB that defines the columns of the grid. This can change by user. Also, I use the same grid to edit several sets of data. I have the proper Imports and the code compiles without error. I run this code before I bind the data to the grid. Any help would be greatly appreciated!
Dim row As DataRow Dim field As BoundDataField Dim editSettings As EditingColumnSetting Dim dtList As DataTable Dim tbl As DataTable = objDBLayer.GetDataTable(SQL) For Each row In tbl.Rows field = New BoundDataField field.Key = row("vFieldKey") field.DataFieldName = row("vFieldKey") If Not IsDBNull(row("vFieldName")) Then field.Header.Text = row("vFieldName") If Not IsDBNull(row("vToolTip")) Then field.Header.Tooltip = row("vToolTip") field.Width = 100 grdEdit.Columns.Add(field) editSettings = New EditingColumnSetting editSettings.ColumnKey = row("vFieldKey") If Not IsDBNull(row("bEditable")) Then editSettings.ReadOnly = Not row("bEditable") If Not IsDBNull(row("vFieldType")) Then Select Case row("vFieldType") Case "Date" 'add code to create datepicker Case "Percent" 'add code to create percent editor Case "Select" Select Case row("vFieldKey") Case "iCoJobID" Case "iGradeID" Dim ddlGrade As New DropDownProvider ddlGrade.ID = row("vFieldKey") dtList = objDBLayer.GetDataTable("SELECT iGradeID, vGradeName FROM Grade") ddlGrade.EditorControl.DataSource = dtList ddlGrade.EditorControl.DataBind() ddlGrade.EditorControl.TextField = "vGradeName" ddlGrade.EditorControl.ValueField = "iGradeID" ddlGrade.EditorControl.ValueDisplayType = DropDownValueDisplayType.Simple grdEdit.EditorProviders.Add(ddlGrade) editSettings.EditorID = row("vFieldKey") Case "iStructureID" Case "iSurveyID" Case "iSvyJobID" End Select End Select End If grdEdit.Behaviors.EditingCore.Behaviors.CellEditing.ColumnSettings.Add(editSettings) Next
I am uploading a scaled down version of my app. It creates the grids properly and loads the data. It just won't display the dropdown provider or the datepicker provider. I cannot figure out what I'm missing. The dropdown provider should be visible for the Grade column on the Company Jobs grid and the datepicker provider should be visible for the Birthdate column on the Employee grid.
p.s. I didn't include the ig_res folder to reduce the size of the zip file.
Hello Peggy,
Thank you for the code snippet and the sample.
The issue happens because you need to operate with the GridView of the WebHierarchicalDataGrid.
For example:
DropDownProvider wddProvider = new DropDownProvider();
wddProvider.ID = "ChildDropDownProvider";
wddProvider.EditorControl.DataSourceID = "SqlDataSource1";
wddProvider.EditorControl.ValueField = "CategoryID";
wddProvider.EditorControl.TextField = "CategoryName";
WebHierarchicalDataGrid1.EditorProviders.Add(wddProvider);
EditingCore behavior = WebHierarchicalDataGrid1.GridView.Behaviors.CreateBehavior<EditingCore>();
CellEditing cellEditing = behavior.Behaviors.CreateBehavior<CellEditing>();
EditingColumnSetting categorySetting = new EditingColumnSetting(WebHierarchicalDataGrid1.GridView);
categorySetting.ColumnKey = "CategoryID";
categorySetting.EditorID = "ChildDropDownProvider";
cellEditing.ColumnSettings.Add(categorySetting);
In your sample you should just modify the last row :
grdEdit.GridView.Behaviors.EditingCore.Behaviors.CellEditing.ColumnSettings.Add(editSettings)
Let me know if you have further questions.
P.S: Please refer to the below article regarding the Hierarchical View of the WHDG:
http://help.infragistics.com/NetAdvantage/ASPNET/2010.3?page=WebHierarchicalDataGrid_Hierarchical_View.html
A little more information...
I created a new form and used the WebDataGrid instead of the WHDG. Using the same code (except that I moved the datasource and databind lines below the assignment of the textfield and valuefield) to create the dropdown provider works in the WDG but not in the WHDG.