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

Wich event can I use when removing an Item?

7 Answers 124 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Carlos
Top achievements
Rank 2
Carlos asked on 08 Aug 2011, 06:27 PM
I'm using RadUpload and a GridView in order to give the user the chance of configurating each file in my appliction context...  When a user add files to upload I add rows in the DataGrid.. but when the user chooses to remove a previously selected file I just can't grab the event and consequently update the gridView...

NOTE: I'm using a ViewModel (MVVM)

please check the image for a better idea...

Any help would be appreciated,
Thanks

7 Answers, 1 is accepted

Sort by
0
Carlos
Top achievements
Rank 2
answered on 10 Aug 2011, 01:56 AM
Any thoughts
0
Accepted
Alex Fidanov
Telerik team
answered on 10 Aug 2011, 07:49 AM
Hi Carlos,

If I understood your scenario correctly, you want to hook up to an event of the upload control when the item is removed. If that is the case, then you can use the RadUploadItem's Delete event. It will be raised when the upload item is removed by clicking on its delete icon. Is this how an item is deleted in your scenario? Please let me know if that event works for you. Please note that you can attach to it using the EventManager.RegisterClassHandler method.

Best wishes,
Alex Fidanov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Carlos
Top achievements
Rank 2
answered on 10 Aug 2011, 02:59 PM
Ah... I don't know if you got it, but I want to grab the event that would fire after I click on the "X" of the RadUploadItem, I think you got that..

but my RadUploadItem's are dinamically added (like is normal with this kind of component)... and I use a ViewModel class to "control" my UserControl...

The radUpload xaml is:

<telerik:RadUpload
                        Grid.Column="1" Grid.Row="0"
                        x:Name="radUpload" Margin="2 0 0 0"
                        Filter="Text Files (*.txt)|*.txt|Image Files(*.gif;*.jpg;*.jpeg;*.png)|*.gif;*.jpg;*.jpeg;*.png|All Files(*.*)|*.*"
                        FilterIndex="3" IsMultiselect="True" MaxFileCount="{Binding NumeroMaximoFicheirosUpload}" BufferSize="11000000"
                         IsAutomaticUpload="False"
                        OverwriteExistingFiles="True"
                        UploadServiceUrl="../WebServ/DocumentosCarregados.ashx"
                        TargetFolder="../Upload"
                        HorizontalAlignment="Center" VerticalAlignment="Center">
                <swi:Interaction.Triggers>
                    <swi:EventTrigger EventName="FilesSelected">
                        <esi:CallDataMethod Method="radUpload_FilesSelected" />
                    </swi:EventTrigger>
                    <swi:EventTrigger EventName="FileUploadStarting">
                        <esi:CallDataMethod Method="radUpload_FileUploadStarting" />
                    </swi:EventTrigger>
                    <swi:EventTrigger EventName="UploadStarted">
                        <esi:CallDataMethod Method="radUpload_UploadStarted" />
                    </swi:EventTrigger>
                    <swi:EventTrigger EventName="UploadCanceled">
                        <esi:CallDataMethod Method="radUpload_UploadCanceled" />
                    </swi:EventTrigger>
                    <swi:EventTrigger EventName="FileUploaded">
                        <esi:CallDataMethod Method="radUpload_FileUploaded" />
                    </swi:EventTrigger>
                </swi:Interaction.Triggers>
            </telerik:RadUpload>

Can you please explain how to use your former solution? If that solution serves my problem, ofcourse.

Thanks!
0
Carlos
Top achievements
Rank 2
answered on 11 Aug 2011, 05:30 PM
Adding to my previous question, it came another problem to resolve...

I must be able to stop the uploading process in the very beggining of it if I have some bad (custom) validation result in my GridView.. (for visual reference please check the attached file on my first post).

Example: Image that I wanted to show a confirm dialog with "Ok" and "Cancel" when the user clicks the Upload button... how should I proceed if the user clicks "Cancel"? I mean, canceling the Upload without cleaning the items in the RadUpload control?

I've tried to poorly work arround the problem with:

      
public void radUpload_UploadStarted(object sender, UploadStartedEventArgs e)
{
        if (cancelar == true)
        {
                Collection<RadUploadSelectedFile> lista = RU.CurrentSession.SelectedFiles;
                RU.CancelUpload();
                RU.CurrentSession.SelectedFiles = lista;
         }
}

But, the aproach is lame, RU.CurrentSession.SelectedFiles is ReadOnly and lista is copied by reference so when RU.CurrentSession.SelectedFiles  gets empty, lista does also...

Can you please help me with these two problems?
0
Accepted
Petar Mladenov
Telerik team
answered on 15 Aug 2011, 12:02 PM
Hello Carlos,

 You can try to create a CustomRadUpload control that inherits from RadUpload. Then you have to introduce delete event in it which fires every time when the RadUploadItem's Delete event fires. Then you will be able to use this EventTrigger (As  I managed to understand this is your main goal).
For the second issue, the approarch you have used isn't bad by design, you only have to improve the implementation: you have to "for-each" SelectedFiles in order fill the "lista" collection before invoking the CancelUpload method. Please let us know if this helped you.

Regards,
Petar Mladenov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Carlos
Top achievements
Rank 2
answered on 29 Aug 2011, 11:00 AM
I was on vacation for 2 weeks and read your answer only now.

I don't see how I can get the RadUploadItem's reference as soon as I add files into RadUpload.

At the end of the method:
       public void radUpload_FilesSelected(object sender, FilesSelectedEventArgs e)
        { ... } I can't find any RadUploadItem when I call the following method:

        void pesquisaRadUploadItems(object sender)
        {
            IList<RadUploadItem> xpto = ((RadUpload)sender).ChildrenOfType<RadUploadItem>();
        }

Only when I fire another radUpload event, like cancel or upload, I am able to find those radUploadItem's, and eventually I would manage to "connect" the Deleted events for each radUploadItem into my custom method.
0
Carlos
Top achievements
Rank 2
answered on 29 Aug 2011, 02:59 PM
For now it is working well. I've used the "EventManager.RegisterClassHandler ".

Before my vacations I should have been sleeping because I couldn't put this to work with the solution I've used now!

Thank you both for your precious help :)
Tags
Upload
Asked by
Carlos
Top achievements
Rank 2
Answers by
Carlos
Top achievements
Rank 2
Alex Fidanov
Telerik team
Petar Mladenov
Telerik team
Share this question
or