0

i have a datagrid bound to a property. In this grid i have columns which consists of cells which are like hyperlink i mean when user clicks on the cell value based on these values another gird will get populated. i want to know how to get the cell value and pass it to some method so that other grid will get populated.

neo
  • 64
  • 1
  • 1
  • 9

1 Answers1

0

The best way to do this is in your viewmodel.

You should bind the SelectedItem of your datagrid to a new property in your ViewModel. In the set method of this new Property, call a new method to populate a new ObservableCollection/List/whatever...

Finally, bind your "other grid" ItemsSource to this new observable collection from your ViewModel.

Edit: If you need to load one thing or another depending on the column you are going to use the code behind, take a look at this: Silverlight DataGrid how to get cell value from a selected item?

Community
  • 1
  • 1
zapico
  • 2,396
  • 1
  • 21
  • 45
  • but the problem is i want to pass the selected cell value and its column name as a parameter. – neo Sep 13 '12 at 10:18
  • it is bound to ObservableCollection. – neo Sep 13 '12 at 10:25
  • Then you have to make a SomeClass property and bind your SelectedItem to it. Then you can use the SomeClass property you want to load the new ObservableCollection. – zapico Sep 13 '12 at 10:28
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/16633/discussion-between-neo-and-zapico) – neo Sep 13 '12 at 10:33
  • private Effort cellSelected; public Effort CellSelected { get { return cellSelected; } private set { if (cellSelected != value) { cellSelected = value; NotifyPropertyChanged("CellSelected"); } } } here i have declared the property but how would i know which column and value the user selected? – neo Sep 13 '12 at 10:34
  • That's what I mean when I say you'll have to use code behind. I can't think of anyway doing it through MVVM 8-) – zapico Sep 13 '12 at 10:43
  • Take a look at this other one http://stackoverflow.com/questions/1089650/silverlight-datagrid-celltemplate-binding-to-viewmodel?rq=1 – zapico Sep 13 '12 at 10:45
  • Thanks. i think its only way out. – neo Sep 13 '12 at 10:59