Private Sub dgv_EditorRequired(sender As Object, e As EditorRequiredEventArgs) Handles dgv.EditorRequired
Select Case dgv.CurrentRow.Cells("EditorType").Value
Case EditorType.OfficeDropDown
Dim editor As New RadDropDownListEditor
editor.DropDownStyle = RadDropDownStyle.DropDownList
DirectCast(editor.EditorElement, RadDropDownListEditorElement).DataSource = dtOffices
DirectCast(editor.EditorElement, RadDropDownListEditorElement).DisplayMember = "OfficeName"
DirectCast(editor.EditorElement, RadDropDownListEditorElement).ValueMember = "OfficeNumber"
e.Editor = editor
End Select
End Sub
10 Answers, 1 is accepted
Thank you for writing.
GridViewComboBoxColumn allows you to select from a list of predefined options. The GridViewComboBoxColumn.DisplayMember property controls what to be displayed in the grid cells. However, if you use a GridViewTextBoxColumn and change the editor in the EditorRequired event, it is necessary to set the RadDropDownListEditorElement.ValueMemebr property to the value that you want to be displayed in the cell. Currently, it is set to the OfficeNumber. That is why it is stored in the cell. Set it to the OfficeName.
I hope this information helps. Should you have further questions I would be glad to help.
Regards,
Dess
Telerik by Progress

Hi Dess
When the user clicks a button on the form, I need to be able to get the OfficeNumber for the office that's selected in that cell. If I set the ValueMember to OfficeName, how would I get the OfficeNumber?
Thank you for writing back.
If you set the ValueMember property to OfficeName, you can't get the OfficeNumber unless you iterate the DataSource collection and find the respective record and the OfficeNumber considering the OfficeName.
In addition to the case with using the GridViewTextBoxColumn, you can set the ValueMember property to OfficeNumber, but control what to be displayed in the grid cells by using the CellFormatting event where you can specify the CellElement.Text property. Feel free to use this approach which suits your requirement best.
I hope this information helps. If you have any additional questions, please let me know.
Regards,
Dess
Telerik by Progress

Dess, can you elaborate on how to use CellFormatting to set the CellElement.Text property in this case? I too am trying to implement this and finding each id for many unknown rows is proving challenging.
Thanking you in advance.
Thank you for writing.
Have you looked at the GridViewComboBoxColumn's documentation and whether it suits your case? What kind of value you want to store in the cells and what to be displayed? What kind of an editor do you need to activate for the column? Once you provide some details about the exact case that you have we can think about a suitable solution and assist you further. Thank you in advance.
I am looking forward to your reply.
Regards,
Dess
Progress Telerik

Dess,
I am needing an example of how to use the grids CellFormatting event to hold the underlining ID for my comboboxes in the grid cell tag property.
For example, in the imaged attached, how would I store the ID for the selected item in the cell tag?
Can you advise?

Thank you for writing back.
Following the provided information I have prepared a sample project for your reference.
I hope this information helps. If you have any additional questions, please let me know.
Regards,
Dess
Progress Telerik

Dess,
Thank you for your response. It helped me to come up with a solution suited to my needs. (See code).
However, I noticed that if I selected a value in a combobox, then return to that cell, the previously selected value is not selected in the combobox. Can you advise how to achieve this?
Additionally, I am attempting to use a RadMaskedEditBoxEditor for the Attribute Types of numeric. Can you advise how I can set properties on the editor, such as MaskType, Mask, and PromptChar?
Private Sub gvBuildingData_EditorRequired(sender As Object, e As EditorRequiredEventArgs) Handles gvBuildingData.EditorRequired
If gvBuildingData.MasterTemplate.CurrentRow.Cells("AttributeTypeName").Value = "List of items" Then
e.EditorType = GetType(RadDropDownListEditor)
Else
e.EditorType = GetType(RadMaskedEditBoxEditor)
End If
End Sub
Private Sub gvBuildingData_CellEditorInitialized(sender As Object, e As GridViewCellEventArgs) Handles gvBuildingData.CellEditorInitialized
Dim WorkAreaAttributeID As Guid = Guid.Parse(gvBuildingData.MasterTemplate.CurrentRow.Cells("WorkAreaAttributeID").Value.ToString)
If e.Column.HeaderText.ToString.Contains("WA") And gvBuildingData.MasterTemplate.CurrentRow.Cells("AttributeTypeName").Value = "List of items" Then
Dim editor As RadDropDownListEditor = DirectCast(gvBuildingData.ActiveEditor, RadDropDownListEditor)
Dim editorElement As RadDropDownListEditorElement = DirectCast(editor.EditorElement, RadDropDownListEditorElement)
If gvBuildingData.MasterTemplate.CurrentRow.Cells("Attribute").Value = "Work Area Type" Then
dsWorkAreaTypes = _WorkAreaType_Select("Select_Active")
If dsWorkAreaTypes.Tables.Count > 0 Then
editorElement.DataSource = dsWorkAreaTypes.Tables(0)
editorElement.DisplayMember = "Name"
editorElement.ValueMember = "WorkAreaTypeID"
Else
' No work area type values exist
End If
Else
dsWorkAreaAttributeItems = _WorkAreaAttributeItem_Select("Select_All", WorkAreaAttributeID)
If dsWorkAreaAttributeItems.Tables.Count > 0 Then
editorElement.DataSource = dsWorkAreaAttributeItems.Tables(0)
editorElement.DisplayMember = "Item"
editorElement.ValueMember = "ItemID"
Else
' No work area attribute item values exist
End If
End If
editorElement.SelectedValue = Nothing
editorElement.SelectedValue = gvBuildingData.CurrentCell.Value
End If
End Sub
Private Sub gvBuildingData_CellFormatting(sender As Object, e As CellFormattingEventArgs) Handles gvBuildingData.CellFormatting
If e.Column.Name.Contains("WA") Then
If e.Row.Cells("AttributeTypeName").Value = "List of items" Then
If e.Row.Cells(e.Column.Name).Value IsNot Nothing Then
Dim cellValue As Guid = Guid.Parse(e.Row.Cells(e.Column.Name).Value)
Dim attribute As String = e.Row.Cells("Attribute").Value
e.CellElement.Text = _GetTextByValue(attribute, cellValue).ToString()
End If
End If
End If
End Sub
Private Function _GetTextByValue(attribute As String, cellValue As Guid) As Object
Select Case attribute
Case "Work Area Type"
For Each row As DataRow In dsWorkAreaTypes.Tables(0).Rows
If row("WorkAreaTypeID") = cellValue Then
Return row("Name").ToString()
End If
Next
Case Else
For Each row As DataRow In dsWorkAreaAttributeItems.Tables(0).Rows
If row("ItemID") = cellValue Then
Return row("Item").ToString()
End If
Next
End Select
Return String.Empty
End Function
Thank you for writing back.
It is very important the grid's cell value to be identical type with the ValueMember property of the editor. Because when you set the RadDropDownListEditorElement.SelectedValue property in the CellEditorInitialized event it is synced with the cell value. This behavior is available in the previously attached sample project.
As to the RadMaskedEditBoxEditor, in the CellEditorInitialized you can set the mentioned properties for the RadMaskedEditBoxEditorElement which can be accessed by the EditorElement property.
I hope this information helps. If you have any additional questions, please let me know.
Regards,
Dess
Progress Telerik