How to change current row's cell value

2 posts, 0 answers
  1. Sat
    Sat avatar
    7 posts
    Member since:
    Dec 2016

    Posted 21 Jan Link to this post

    I have a grid view which gets its data from database using a view model:

    public class MyDataSource
    {
        MyContext context;
        public MyDataSource()
        {
            context = new MyContext();
            this.Inbox = new ObservableCollection<GetNewData_Result>();
     
            LoadOperation<GetNewData_Result> loadOperation = context.Load<GetNewData_Result>(context.GetNewDataQuery());
            loadOperation.Completed += loadOperation_Completed;
     
        }
        public ObservableCollection<GetNewData_Result> Inbox
        {
            get;
            set;
        }
     
        private void loadOperation_Completed(object sender, EventArgs e)
        {
            foreach (var c in context.GetNewData_Result)
            {
                this.Inbox.Add(c);
            }
        }
    }

     

    Here's my radgridview:

    <telerik:RadGridView 
                     x:Name="DataGridVarde" ItemsSource="{Binding Source={StaticResource DataSource}, Path=Inbox}"
                     AutoGenerateColumns="False">
    <telerik:RadGridView.Columns>
        <telerik:GridViewImageColumn  Header="" DataMemberBinding="{Binding Path=Seen,Converter={StaticResource IsSeen}}"  ImageStretch="None" />
        ////

     

    As you can see I have defined a converter for one of my fields, This field simply is a toggle image, if the value is true it shows a image otherwise it shows another image:

    public object Convert(object value,
           Type targetType,
           object parameter,
           CultureInfo culture)
    {
        if (value is Boolean)
        {
            Boolean state = (Boolean)value;
            if (state)
                return "/Path;component/img/open.png";
            else
                return "/Path;component/img/close.png";
        }
        else
        {
            throw new ArgumentException("Value should be Boolean type.");
        }
    }

     

    This works great after each post back (navigating between pages). But I want to change it without refreshing the page. Is it possible? for example when someone click on a button I want to change that column's value to false or actually invoking the converter with `False` value so that it shows another image.

     

    I have tried this code but it doesn't work:

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        string code = (dataGridView.SelectedItem as GetNewData_Result).mycode;
        var row = (dataGridView.ItemsSource as ObservableCollection<GetNewData_Result>).FirstOrDefault(p => p.Code == code);
        if (row.Seen)
        {
            row.Seen = false;
        }

     

    PS: I can't define a custom class that implements INotifyPropertyChange for some reasons. As you can see the data comes from a generated stored procesdure so that I can't have control to define a custom type to return by this function ( context.GetNewDataQuery() )

     

    Any idea?

     

    Thanks in advance

  2. Sat
    Sat avatar
    7 posts
    Member since:
    Dec 2016

    Posted 24 Jan Link to this post

    Any idea?
Back to Top