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

How to change current row's cell value

1 Answer 92 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sat
Top achievements
Rank 1
Sat asked on 21 Jan 2017, 07:38 PM

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

1 Answer, 1 is accepted

Sort by
0
Sat
Top achievements
Rank 1
answered on 24 Jan 2017, 06:45 PM
Any idea?
Tags
GridView
Asked by
Sat
Top achievements
Rank 1
Answers by
Sat
Top achievements
Rank 1
Share this question
or