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

updating values of an entire column MVVM

0 Answers 91 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Avi
Top achievements
Rank 1
Avi asked on 17 Apr 2012, 01:36 PM

Hello,

I am looking at your demo for "CustomFilterControls". But I do not want to filter I want to update my column with new value. I add an attach picture file to this post for demo.

At this picture we see that the user want to update the all "f" column to new value 23.

I write this code :

XAML:

<Border x:Name="LayoutRoot"
           Background="#FFDFE2E5"
           BorderBrush="#FF8A929E"
           BorderThickness="1"
           Padding="5">
       <Grid>
           <Grid.RowDefinitions>
               <RowDefinition Height="Auto" />
               <RowDefinition Height="Auto" />
               <RowDefinition Height="Auto" />
           </Grid.RowDefinitions>
           <TextBlock Margin="2">New Value:</TextBlock>
           <TextBox Name="newValue"
                    Grid.Row="1"
                    Margin="2" />
           <telerik:RadButton Name="updateButton"
                              Grid.Row="2"
                              Width="80"
                              Margin="2"
                              Click="OnUpdate"
                              Content="Update" />
       </Grid>
   </Border>

Code :

public partial class UpdateColumnControl : UserControl, IFilteringControl
  {     
 
       private GridViewBoundColumnBase column;
       private CompositeFilterDescriptor compositeFilter;
       private FilterDescriptor newValueFilter;     
 
       /// <summary>
       /// Gets or sets a value indicating whether the filtering is active.
       /// </summary>
       public bool IsActive
       {
           get { return (bool)GetValue(IsActiveProperty); }
           set { SetValue(IsActiveProperty, value); }
       }
 
       /// <summary>
       /// Identifies the <see cref="IsActive"/> dependency property.
       /// </summary>
       public static readonly DependencyProperty IsActiveProperty =
           DependencyProperty.Register(
               "IsActive",
               typeof(bool),
               typeof(UpdateColumnControl),
               new System.Windows.PropertyMetadata(false));
 
       [TypeConverter(typeof(string))]
       public string NewValue
       {
           get { return this.newValue.Text; }
           set { this.newValue.Text = value; }
       }
        
       public TextBox NewValuePicker
       {
           get { return this.newValue; }
       }      
 
       public UpdateColumnControl()
       {
           InitializeComponent();
       }
 
       public void Prepare(GridViewBoundColumnBase column)
       {
           this.column = column as GridViewBoundColumnBase;
           if (this.column == null)
           {
               return;
           }
            
           if (this.compositeFilter == null)
           {
               this.CreateFilters();
           }
 
           this.newValueFilter.Value = this.NewValue;         
       }
 
       private void CreateFilters()
       {
           string dataMember = this.column.DataMemberBinding.Path.Path;
            
           this.compositeFilter = new CompositeFilterDescriptor();
 
           this.newValueFilter = new Telerik.Windows.Data.FilterDescriptor(dataMember
               , Telerik.Windows.Data.FilterOperator.IsGreaterThanOrEqualTo
               , null);
           this.compositeFilter.FilterDescriptors.Add(this.newValueFilter);
          
       }
 
       private void OnUpdate(object sender, RoutedEventArgs e)
       {
           this.newValueFilter.Value = this.NewValue;          
 
           if (!this.column.DataControl.FilterDescriptors.Contains(this.compositeFilter))
           {
               this.column.DataControl.FilterDescriptors.Add(this.compositeFilter);
           }
            
           this.IsActive = true;           
       }              
   }

My Question is how can I update my ViewModel with the new value (I am working with MVVM) from the Custom Filter Control ?

private void clubsGrid_Filtered(object sender, GridViewFilteredEventArgs e)

OR

private void clubsGrid_Filtering(object sender, GridViewFilteringEventArgs e)


Because these events not firing and I read here why it's not working.

Also The column instance inside the filtering control :

public void Prepare(GridViewBoundColumnBase column)
{           
    this.column = column as GridViewBoundColumnBase;
}

Has NO  property "DataControl" which will return the grid instance.
I do it like this :
RadGridView gv = (RadGridView)((GridViewColumn)(column)).DataControl;

But inside RadGridView (gv) there is no ItemsSource property that I can cast its ItemsSource property to my needed collection

Thanks,
Aviv

       

Tags
GridView
Asked by
Avi
Top achievements
Rank 1
Share this question
or