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

GridViewBrowseColumn SelectedFile Event

10 Answers 200 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Brendan
Top achievements
Rank 1
Brendan asked on 10 Apr 2013, 04:11 AM
I have a RadGrid with 4 columns;
- Checkbox,
- Image,
- TextBox,
- BrowseColumn
What I want to do is update the first 3 columns based on the filename selected from the Dialog in column 4.  I have tried ValueChanging events, validation etc. but they don't do what I need. Specifically;

1. User clicks the 'Add New Row' button
2. I want to set the focus/editor on col 4
3. User clicks the '...' dialog button in col 4 and opens the FileDialog
4. User selects a filename, FileDialog closes
5. I want to trap the event now so I can insert values into cols 1-3.

All the other events I tried do not fire until the cell loses focus or enter is pressed etc.  I want to fire as soon as the Dialog.FileName is returned to the cell.  Anyone know how to do this?  Thanks.

10 Answers, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 12 Apr 2013, 01:34 PM
Hi Brendan,

Thank you for writing.

You can subscribe for the CellEditorInitlialized event to gain access to the grid editor. Having the editor you can subscribe for its events. Here is an example which shows how to get the filename of the file selected through the open file dialog:
private void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
    GridBrowseEditor editor = e.ActiveEditor as GridBrowseEditor;
    GridBrowseEditorElement element = editor.EditorElement as GridBrowseEditorElement;
 
    element.DialogClosed += element_DialogClosed;
}
 
private void element_DialogClosed(object sender, DialogClosedEventArgs e)
{
    if (e.DialogResult == System.Windows.Forms.DialogResult.OK)
    {
        GridBrowseEditorElement element = sender as GridBrowseEditorElement;
 
        string filename = ((OpenFileDialog)element.Dialog).FileName;
    }
}

I hope this will be useful. Should you have further questions, I would be glad to help.

Greetings,
Ivan Petrov
the Telerik team
WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
0
Brendan
Top achievements
Rank 1
answered on 12 Apr 2013, 05:45 PM
Thanks Ivan, that gets me part way there.  In my code below I get the filename but I then want to set col 1 (checkbox to checked) and col 3 (textbox = filename without extension) based on this value. 

In my VB code below, how can I 'get' the pending/new row to make these insertions in the dialog closed section?

Private Sub grdMyAppsSetup_CellEditorInitialized(sender As Object, e As GridViewCellEventArgs) Handles grdMyAppsSetup.CellEditorInitialized
     Dim editor As GridBrowseEditor = TryCast(e.ActiveEditor, GridBrowseEditor)
     If Not editor Is Nothing Then   'are we in edit mode?
         Dim element As GridBrowseEditorElement = TryCast(editor.EditorElement, GridBrowseEditorElement)
         'addhandler for grdEditRow event
        AddHandler element.DialogClosed, AddressOf grMyAppSetup_DialogClosed
    End If
 End Sub
 
Private Sub grMyAppSetup_DialogClosed(sender As Object, e As DialogClosedEventArgs)
     If e.DialogResult = System.Windows.Forms.DialogResult.OK Then
        Dim element As GridBrowseEditorElement = TryCast(sender, GridBrowseEditorElement)
        Dim sFileName As String = DirectCast(element.Dialog, OpenFileDialog).FileName
 
        If sFileName.Length > 0 Then 'perform file operations here
 
            Dim txtFile As String = Path.GetFileNameWithoutExtension(sFileName)
            ' HOW Can I insert txtFile into col 3, which is a textbox column
            ' ie: how do I access the new/pending row ?
        End If
     End If
 End Sub
0
Accepted
Ivan Petrov
Telerik team
answered on 17 Apr 2013, 11:04 AM
Hello Brendan,

Thank you for your reply.

Cells in the New row of RadGridView can be accessed as with any other row. In your case you are in edit mode so the current row is the new row. You can directly set the cells' values to the grid view current row. Here is how your code will look like:
Private Sub grMyAppSetup_DialogClosed(sender As Object, e As DialogClosedEventArgs)
    If e.DialogResult = System.Windows.Forms.DialogResult.OK Then
        Dim element As GridBrowseEditorElement = TryCast(sender, GridBrowseEditorElement)
        Dim sFileName As String = DirectCast(element.Dialog, OpenFileDialog).FileName
 
        If sFileName.Length > 0 Then 'perform file operations here
 
            Dim txtFile As String = Path.GetFileNameWithoutExtension(sFileName)
            Me.RadGridView1.CurrentRow.Cells("CheckBoxCol").Value = True
            Me.RadGridView1.CurrentRow.Cells("TextBoxCol").Value = txtFile
        End If
    End If
End Sub

I hope this helps. Feel free to write back with any further questions.

Kind regards,
Ivan Petrov
the Telerik team
WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
0
Brendan
Top achievements
Rank 1
answered on 17 Apr 2013, 03:18 PM
Thank Ivan, it seems too simple now when I see it.

I also added some code at the top of the CellEditorInitialized event to move focus to the cell with the GridBrowser column.  Here is the code in case other readers may be curious.

        'set focus to filename column
        Me.grdMyRadGrid.CurrentRow.Cells("colFile").BeginEdit()

Now when I click the 'Add New Row' bar, the GridBrowser Column always gains focus, and the user is prompted to find a file.
0
Ivan Petrov
Telerik team
answered on 19 Apr 2013, 01:14 PM
Hello Brendan,

Thank you for writing back.

Thank you for sharing your solution with the community.

I am glad we have been able to find solutions to your problems. Do not hesitate to write back for further assistance.

Greetings,
Ivan Petrov
the Telerik team
WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
0
Brendan
Top achievements
Rank 1
answered on 22 Jul 2013, 09:39 PM
Hi Ivan, I have another question relating to the GridBrowseEditor and thought it best to continue in this thread.

Is it possible to set a filter selection on the dialog (ie: like fileDialogBox.Filter ?).  I looked in the BaseInputEditor, GridBrowseEditor, GridBrowseEditorElement,and in the Object Browser under RadBrowserEditorElement at CreateOpenFileDialog but wasn't sure how to implement it or if it was the answer.

Can a file filter and initial folder path be set?  (eg: fileDialogBox.Filter = "Excel Documents XML (*.xml)|*.xml" )

Thanks, Brendan
0
Ivan Petrov
Telerik team
answered on 25 Jul 2013, 03:14 PM
Hello Brendan,

Thank you for your reply.

You can access the dialog of RadBrowseEditor through the Dialog property. This property holds the dialog that will be shown based on the DialogType property. Here is how you can set a filter to a OpenFileDialog:
RadBrowseEditor editor = new RadBrowseEditor();
editor.DialogType = BrowseEditorDialogType.OpenFileDialog;
OpenFileDialog openFileDialog = editor.Dialog as OpenFileDialog;
openFileDialog.Filter = "Excel Documents XML (*.xml)|*.xml";

The dialog property is of the base type of the available dialogs so you will have to cast it to the proper type.

I hope this will be of use. Should you have further questions, feel free to write back.

Regards,
Ivan Petrov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Brendan
Top achievements
Rank 1
answered on 25 Jul 2013, 05:56 PM
Thanks Ivan, however I am not sure how to connect the RadBrowseEditor and the GridBrowseEditorElement.  In the code below I cannot create 'element' because EditorElement is not a member of the RadBrowseEditor. 

Dim editor As New RadBrowseEditor()
editor.DialogType = BrowseEditorDialogType.OpenFileDialog
Dim openFileDialog As OpenFileDialog = TryCast(editor.Dialog, OpenFileDialog)
openFileDialog.Filter = "Excel Documents XML (*.xml)|*.xml"
 
If Not editor Is Nothing Then   'are we in edit mode?
    Dim element As GridBrowseEditorElement = TryCast(editor.EditorElement, GridBrowseEditorElement)
 
    'addhandler for grdEditRow event
    AddHandler element.DialogClosed, AddressOf grdMyReportsSetup_DialogClosed
End If
0
Ivan Petrov
Telerik team
answered on 30 Jul 2013, 09:27 AM
Hello Brendan,

Thank you for writing back.

The editors in all controls are a logical connection between the editor and the control. They implement an interface which helps them communicate with the controls they are used in. Each editor has an editor element which is what is added to the controls and what the users see and interact with. Here is how to access the browse editor element from the CellEditorInitialized:
Private Sub RadGridView1_CellEditorInitialized(sender As Object, e As GridViewCellEventArgs) Handles RadGridView1.CellEditorInitialized
    Dim editor As GridBrowseEditor = TryCast(e.ActiveEditor, GridBrowseEditor)
    If editor IsNot Nothing Then
        Dim element As RadBrowseEditorElement = DirectCast(editor.EditorElement, RadBrowseEditorElement)
        Dim openDialog As OpenFileDialog = DirectCast(element.Dialog, OpenFileDialog)
        openDialog.Filter = "Excel Documents XML (*.xml)|*.xml"
    End If
End Sub

I hope this will be useful. Should you have further questions, I would be glad to assist.

Regards,
Ivan Petrov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Brendan
Top achievements
Rank 1
answered on 14 Aug 2013, 04:03 PM
Thanks, that works well.
Tags
GridView
Asked by
Brendan
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Brendan
Top achievements
Rank 1
Share this question
or