RadGridView column with multiple data types - dropdown issue

11 posts, 0 answers
  1. Simon
    Simon avatar
    27 posts
    Member since:
    Aug 2011

    Posted 26 Jan Link to this post

    I have a column with multiple data types. I'm using the EditorRequired event to set the editor as a RadDateTimeEditor or RadDropDownListEditor as needed. In some cases I set the RadDropDownListEditor's datasource to a datatable as shown in the code below. When I click in the cell, the radDropDownListEditor works perfectly, but when I click away from that cell, the cell shows the OfficeNumber (the valueMember) instead of the OfficeName (the displayMember). How do I get it to show the OfficeName?

           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
  2. Dess
    Admin
    Dess avatar
    2196 posts

    Posted 27 Jan Link to this post

    Hello Simon,

    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
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Simon
    Simon avatar
    27 posts
    Member since:
    Aug 2011

    Posted 29 Jan in reply to Dess Link to this post

    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? 

  4. Dess
    Admin
    Dess avatar
    2196 posts

    Posted 30 Jan Link to this post

    Hello Simon, 

    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
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  5. Speedy
    Speedy avatar
    24 posts
    Member since:
    Feb 2016

    Posted 12 Nov in reply to Dess Link to this post

    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.

  6. Dess
    Admin
    Dess avatar
    2196 posts

    Posted 14 Nov Link to this post

    Hello, James,

    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
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  7. Speedy
    Speedy avatar
    24 posts
    Member since:
    Feb 2016

    Posted 14 Nov in reply to Dess Link to this post

    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?

     

     

     

  8. Speedy
    Speedy avatar
    24 posts
    Member since:
    Feb 2016

    Posted 14 Nov in reply to Speedy Link to this post

    I also should have mentioned that the cell editor is changed based off the text in the Attribute Type column.  Just wanted to be sure that you understand that the WA - 0 column is not a combobox, but rather a textbox with a changing editor.
  9. Dess
    Admin
    Dess avatar
    2196 posts

    Posted 15 Nov Link to this post

    Hello, James,    

    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
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  10. James
    James avatar
    1 posts
    Member since:
    Jan 2013

    Posted 15 Nov in reply to Dess Link to this post

    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
  11. Dess
    Admin
    Dess avatar
    2196 posts

    Posted 17 Nov Link to this post

    Hello, James,    

    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
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top