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

Passing Grid's Selected Item to RadWindow

3 Answers 131 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Laura Edwards
Top achievements
Rank 1
Laura Edwards asked on 12 Aug 2010, 08:47 PM
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?

3 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 16 Aug 2010, 01:17 PM
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
0
Laura Edwards
Top achievements
Rank 1
answered on 16 Aug 2010, 02:26 PM
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?
0
Maya
Telerik team
answered on 19 Aug 2010, 11:24 AM
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
Tags
GridView
Asked by
Laura Edwards
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Laura Edwards
Top achievements
Rank 1
Maya
Telerik team
Share this question
or