Passing Grid's Selected Item to RadWindow

4 posts, 0 answers
  1. Laura Edwards
    Laura Edwards avatar
    25 posts
    Member since:
    Jun 2010

    Posted 12 Aug 2010 Link to this post

    Hi, I am having trouble with setting a radcombobox's selected value to a gri'd selected item.

    Scenario:

    I have a user control(the main grid) that is populated with records via it's itemsource. In the row I have a button(for deletion). I want to reference the item in the row with the button, so that when I push the button a new user control (the rad window) opens with a combobox with the selected row's item already selected.

    The combobox is set to the same item source as the grid.

    Is there a way to do this?
  2. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 16 Aug 2010 Link to this post

    Hi Laura Edwards,

    Yes, this is possible. Please check the attached sample application.

    Hope it will get you started.

    All the best,
    Veselin Vasilev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Laura Edwards
    Laura Edwards avatar
    25 posts
    Member since:
    Jun 2010

    Posted 16 Aug 2010 Link to this post

    This is exactly what I was hoping for. One thing though. Is there a way to do this using commands and command parameter to follow MVVM?
  5. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 19 Aug 2010 Link to this post

    Hello Laura Edwards,

    As your requirement is to have additional UserControl - in this case a RadWindow, the pure MVVM will not be accomplished, mainly becasue the ViewModel is not supposed to be aware of the View. 
    However, you may use one of the  following approaches to keep the MVVM structure as pure as possible:
    1. You can define the command in the ViewModel as follows:

    public ICommand InfoCommand
    {
        get
        {
            if (infoCommand == null)
            {                  
                infoCommand = new DelegateCommand<Club>(this.GetItemInfo);
            }
            return infoCommand;
        }
    }
     
    public void GetItemInfo(Club club)
    {
        RadWindow wnd = new RadWindow();
        PopupControl popup = new PopupControl();
        popup.combo.ItemsSource = this.Clubs;
        popup.combo.SelectedItem = club;
        wnd.Content = popup;
        wnd.WindowStartupLocation = Telerik.Windows.Controls.WindowStartupLocation.CenterOwner;
        wnd.Show();
     
    }  

     However, in this case the ViewModel needs to be aware of the PopupControl implemented.
    2. You may define an Action that will be called upon firing the command. This Action will be executed on the Loaded event.
    public ICommand InfoWithActionCommand
    {
        get
        {
            if (infoWithActionCommand == null)
            {
                infoWithActionCommand = new DelegateCommand<Club>(this.OnPopUpInvokedAction);
            }
            return infoWithActionCommand;
        }
    }
     
    public Action<Club> OnPopUpInvokedAction
    {
        get;
        set;
    }
     
    private void clubsGrid_Loaded(object sender, RoutedEventArgs e)
    {
        var viewModel = this.Resources["MyViewModel"] as MyViewModel;
     
        viewModel.OnPopUpInvokedAction = (c) =>
        {
            RadWindow wnd = new RadWindow();
            PopupControl popup = new PopupControl();
            popup.combo.ItemsSource = viewModel.Clubs;
            popup.combo.SelectedItem = c;
            wnd.Content = popup;
            wnd.WindowStartupLocation = Telerik.Windows.Controls.WindowStartupLocation.CenterOwner;
            wnd.Show();
        };
    }

    I am sending you a sample project illustrating both solutions.



    Kind regards,
    Maya
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top