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