This is a migrated thread and some comments may be shown as answers.

GridViewBrowseColumn Multi-Select

3 Answers 77 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jacob
Top achievements
Rank 1
Jacob asked on 08 Apr 2019, 09:35 PM

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

3 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 09 Apr 2019, 08:05 AM
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.
0
Jacob
Top achievements
Rank 1
answered on 09 Apr 2019, 03:25 PM

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)

0
Dimitar
Telerik team
answered on 10 Apr 2019, 06:03 AM
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 and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
Jacob
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Jacob
Top achievements
Rank 1
Share this question
or