GridViewBrowseColumn Multi-Select

4 posts, 0 answers
  1. Jacob
    Jacob avatar
    2 posts
    Member since:
    Oct 2018

    Posted 08 Apr 2019 Link to this post

    Hello,

     

    When I set the multi-select to true, it allows me to select multiple files, but when I click "Open" on the open file dialog, it only displays ONE of the files I selected. How can it display all files I selected?

     

    Thank you

  2. Dimitar
    Admin
    Dimitar avatar
    2892 posts

    Posted 09 Apr 2019 Link to this post

    Hello Jacob,

    You will need to create a custom editor element and override the SaveValueFromDialog method so that you can extract the values from the multiple file names and use them as a value of the cell. Please check my code snippet below:  
    Partial Public Class RadForm1
        Inherits Telerik.WinControls.UI.RadForm
     
        Public Sub New()
            InitializeComponent()
            AddHandler radGridView1.EditorRequired, AddressOf RadGridView1_EditorRequired
            Dim column As New GridViewBrowseColumn("Browse column")
     
     
            Me.radGridView1.Columns.Add(column)
            Me.radGridView1.Rows.Add("C:\Music\Sting\If You Love Somebody Set Them Free.wav")
            Me.radGridView1.Rows.Add("C:\Music\Sting\Russians.wav")
            Me.radGridView1.Rows.Add("C:\Music\Sting\Fortress Around Your Heart.wav")
            Me.radGridView1.Rows.Add("C:\Music\Sting\Love Is the Seventh Wave.wav")
            Me.radGridView1.Rows.Add("C:\Music\Sheryl Crow\Run, Baby, Run.wav")
            Me.radGridView1.Rows.Add("C:\Music\Sheryl Crow\Leaving Las Vegas.wav")
            Me.radGridView1.Rows.Add("test")
     
            AddHandler radGridView1.CellEditorInitialized, AddressOf RadGridView1_CellEditorInitialized
        End Sub
     
        Private Sub RadGridView1_EditorRequired(ByVal sender As Object, ByVal e As EditorRequiredEventArgs)
            If e.EditorType Is GetType(GridBrowseEditor) Then
                e.EditorType = GetType(MyGridBrowseEditor)
            End If
        End Sub
     
        Private Sub RadGridView1_CellEditorInitialized(ByVal sender As Object, ByVal e As GridViewCellEventArgs)
            Dim editor = TryCast(e.ActiveEditor, GridBrowseEditor)
            If editor IsNot Nothing Then
                Dim element = TryCast(editor.EditorElement, RadBrowseEditorElement)
                Dim dlg = TryCast(element.Dialog, OpenFileDialog)
                dlg.Multiselect = True
     
            End If
        End Sub
     
    End Class
    Public Class MyGridBrowseEditor
        Inherits GridBrowseEditor
     
        Protected Overrides Function CreateEditorElement() As RadElement
            Return New MyRadBrowseEditorElement()
        End Function
    End Class
     
    Public Class MyRadBrowseEditorElement
        Inherits RadBrowseEditorElement
     
        Protected Overrides ReadOnly Property ThemeEffectiveType() As Type
            Get
                Return GetType(RadBrowseEditorElement)
            End Get
        End Property
     
        Protected Overrides Sub SaveValueFromDialog()
            If Me.DialogType <> BrowseEditorDialogType.OpenFileDialog Then
                MyBase.SaveValueFromDialog()
     
                Return
            End If
     
            Dim dialog As OpenFileDialog = TryCast(Dialog, OpenFileDialog)
     
            If dialog IsNot Nothing Then
                Dim value As String = String.Empty
                If dialog.Multiselect Then
                    Dim sb As New StringBuilder()
                    For Each path As String In dialog.FileNames
                        sb.Append(System.IO.Path.GetFileName(path))
                        sb.Append(";")
                    Next path
     
                    value = sb.ToString()
                Else
                    value = dialog.FileName
                End If
     
                Me.Value = value
            End If
        End Sub
    End Class

    I hope this helps. Should you have any other questions do not hesitate to ask.
     
    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboard and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Jacob
    Jacob avatar
    2 posts
    Member since:
    Oct 2018

    Posted 09 Apr 2019 in reply to Dimitar Link to this post

    I am getting a null exception thrown. I believe it is due to the line below. My visual studio is replacing Dialog with dialog

    which is throwing a warning.

     

    Dim dialog As OpenFileDialog = TryCast(Dialog, OpenFileDialog)

  4. Dimitar
    Admin
    Dimitar avatar
    2892 posts

    Posted 10 Apr 2019 Link to this post

    Hello Jacob,

    There is a Dialog property in the base class that should be used in this case. Change the line to:
    Dim dialog As OpenFileDialog = TryCast(Me.Dialog, OpenFileDialog)
     
    Do not hesitate to contact us if you have other questions.
     
    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top