Command executing method on button click
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2

Thread: Command executing method on button click

Hybrid View

  1. #1
    Join Date
    Feb 2013

    Question Command executing method on button click


    I have the below method that takes binary data from sql server, stores it in a observable collection and writes the files to a folder. The problem is when the user clicks the dialog ok button, the ok button has to be clicked for every file in the collection. So if the collection has 5 files that need to be saved the button must be clicked 5 times. I am doing this in a c# wpf app using linq to sql.

    How can this be handled with just one click?

    A relay command is executing this function and the command is bound to the button in xaml.

    private void executeSaveAttachments(object parameter)
                    System.Windows.Forms.FolderBrowserDialog flg = new System.Windows.Forms.FolderBrowserDialog();
                    foreach (var table in Table)
                        if (flg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                            File.WriteAllBytes(Path.Combine(flg.SelectedPath,  table.Title + ".xlsx"), table.Data);

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004

    Re: Command executing method on button click

    Move the if statement containing the flg.ShowDialog() call outside the foreach loop.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This is a survey!

HTML5 Development Center