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

MVVM Grid Binding how to handle Parameters

1 Answer 74 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Daniel asked on 03 Feb 2014, 04:55 PM
Hello I've a RadGridView that is placed withing a RadWindow and wrapped within an UserControl.

The RadWindow will be initialized by an ContextMenu of a parent RadGridView (selected item) please see the code snippets below.

Code from the ContextMenu to open a new RadWindow:

var tmpItem = row.Item as ItemModel;
case "ViewRelatedItems":
         if ( tmpItem != null )
             RadWindow radWindow = new RadWindow();
             radWindow.Width = 510;
             radWindow.Height = 350;
             UserControlRelatedItemsEntries ucTmp = new UserControlRelatedItemsEntries(tmpItem.ID, tmpItem.Type);
             radWindow.Content = ucTmp;
             radWindow.Owner = Application.Current.MainWindow;
             radWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
             radWindow.ResizeMode = ResizeMode.NoResize;
             radWindow.Header = "Entries:"; //TODO

XAML of the UserControl:
<UserControl x:Class="TEST..UserControlViewEntries"
             d:DesignHeight="300" d:DesignWidth="500">
        <viewModel:MyViewModel />
        <telerik:RadGridView x:Name="radGridEntries" Margin="0,30,0,0"
                             ItemsSource="{Binding Entries}"
                             AutoGenerateColumns="False" DataLoadMode="Asynchronous">
                <telerik:GridViewDataColumn DataMemberBinding="{Binding UserName}" Header="User"/>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Date}" Header="Date"/>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding XDoneAsString}" Header="XDone"/>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Description}" Header="Description"/>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Type}" Header="Type"/>

Code of the ViewModel
public class MyViewModel : ObservableObjectBase
        #region Properties
        public int SelectedItemID { get; set; }
        public int SelectedItemTypeID { get; set; }
        private ObservableCollection<XModel> _items;
        public ObservableCollection<XModel> Entries
                if ( _items == null )
                    _items = new ObservableCollection<XModel>();
                    var tmpResults = DataService.GetItems( this.SelectedItemID, this.SelectedItemTypeID);
                    tmpResults.ForEach( i => _items.Add( i ) );
                return _items;
        #region Methods
        #region Constructors
        public MyViewModel ()
        { }

I come here not further...

How can i put the two required values ​​SelectedItemID and SelectedItemTypeID to the ViewModel, so that they can be used when the DataBinding request the the Entries?

I'll hold this 2 values inside the ContextMenu "tmpItem" (e.g. tmpItem.ID and tmpItem.Type) but i've no idea how i could put that throuth the UserControl and ViewModel.

I think I am using the wrong approach... hopefully someone could give me an idea how to solve this issue. 

Any help on this would be very welcome!

Kind regards

1 Answer, 1 is accepted

Sort by
Telerik team
answered on 06 Feb 2014, 03:46 PM

You could bind the SelectedItem of RadGridView to the SelectedItemID in your ViewModel. That way in the ViewModel you will always have the currently selected item. I am not sure what is the purpose of SelectedItemTypeID and how it is used with RadGridView.

You can also check our online documentation on using RadContextMenu with a RadGridView.


Check out the new Telerik Platform - the only modular platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native apps. Register for the free online keynote and webinar to learn more about the Platform on Wednesday, February 12, 2014 at 11:00 a.m. ET (8:00 a.m. PT).

Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question