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

GridViewDataColumn and two way binding

2 Answers 238 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ram
Top achievements
Rank 1
Ram asked on 16 Oct 2013, 01:43 AM
Hi,

I have a gridview, where one of the columns are defined like this:

Two questions:

1)

<telerik:GridViewDataColumn DataMemberBinding="{Binding ApprovedForRI, Mode=TwoWay}"
Header="ApprovedForRI" Width="Auto" IsReadOnly="False"/>

and it is bound to an object, with property like this:

        public override bool ApprovedForRI
        {
            get
            {
                return base.ApprovedForRI;
            }
            set
            {
                base.ApprovedForRI = value;
                OnPropertyChanged("ApprovedForRI");
            }
        }

What I am trying to do is when I check/uncheck the box on UI in ApprovedForRI column, the "set" should get called, so the PropertyChanged event is fired, but I don't see this happening. What is the right way to achieve this.

2)
It seems like to check/uncheck the box, I need three clicks. first to select the cell, 2nd to select the checkbox, and finally 3rd to check/uncheck. Is there any way to make it single click, once row is selected?

Thanks.

2 Answers, 1 is accepted

Sort by
0
Ram
Top achievements
Rank 1
answered on 16 Oct 2013, 11:02 PM
I have solved both the problems, but I am running into another one.
<telerik:GridViewDataColumn EditTriggers="CellClick"
      DataMemberBinding="{Binding ApprovedForRI, Mode=TwoWay"
      Header="ApprovedForRI" Width="Auto" IsReadOnly="False"
      CellStyleSelector="{StaticResource approvedRICellStyleSelector}">
  <telerik:GridViewDataColumn.CellTemplate>
    <DataTemplate>
      <CheckBox   IsChecked="{Binding ApprovedForRI, Mode=TwoWay}" Checked="slr_checked" Unchecked="slr_checked"  />
    </DataTemplate>
  </telerik:GridViewDataColumn.CellTemplate>
  <telerik:GridViewDataColumn.CellEditTemplate>
    <DataTemplate>
      <CheckBox    IsChecked="{Binding ApprovedForRI, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Click="slr_checked"  />
    </DataTemplate>
  </telerik:GridViewDataColumn.CellEditTemplate>
</telerik:GridViewDataColumn>    

public class ApprovedRICellStyleSelector : StyleSelector
{
    public override Style SelectStyle(object item, DependencyObject container)
    {
        if (item is ChangeTableEntity2)
        {
            ChangeTableEntity2 row = item as ChangeTableEntity2;
 
            if (row.ApprovedForRI != row.OriginalApprovedForRI)
            {
                return ChangeCellStyle;
            }
 
            return NormalCellStyle;
        }
        return null;
    }
    public Style ChangeCellStyle { get; set; }
    public Style NormalCellStyle { get; set; }
}

Now I was hoping that with SytleSelector, I would be able to change colors of checkbox when I check/uncheck, but that is not happening. It is always staying the same.



0
Dimitrina
Telerik team
answered on 18 Oct 2013, 11:14 AM
Hi,

You have set CellStyleSelector for the column and it will return proper Style targeting the GridViewCell element. You can refer to our documentation on how this selector works.
In your case you have set your own CellTemplate, which means that the Style you return will be never applied.
Instead, you should apply a Style for the <CheckBox/> you have placed as CellTemplate.
Another note is that you do not need to define CellEditTemplate in that case, you would better set the column to be ReadOnly.

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Ram
Top achievements
Rank 1
Answers by
Ram
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or