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

Binding issue of Checkbox in Cell template

1 Answer 267 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Muhammad Irfan
Top achievements
Rank 1
Muhammad Irfan asked on 25 Aug 2011, 12:27 PM
Hi All,
I am using MVVM pattern in my WPF application. I am using the Modal created by Entity Framework and my ViewModel class have public properties for binding. I have a specific requirements that my GridView should have two checkboxes columns and one TextBox column (all time in Edit mode) and all other remaining columns will be in ReadOnly mode. When user either Check/Uncheck these checkboxes OR change value in TextBox, I will have to do custom calculation on it (Note that for firing these calculation, I should have separate property in ViewModel so that I can fire in its SET clause....Am I right?)
I created the Grid in XAML like this.
<telerik:RadGridView Grid.Column="1" Grid.ColumnSpan="3" Grid.Row="0" Name="radGridView1" AutoGenerateColumns="False" ShowGroupPanel="False"
                             ItemsSource="{Binding IndicatorsList}">
            <telerik:RadGridView.Columns>
                <col:MyColumn Header="#" Width="35"/>
                <telerik:GridViewColumn IsReadOnly="False" Header="Inc." Width="35">
                    <telerik:GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <CheckBox IsChecked="{Binding IncludeIt, Mode=TwoWay}"/>
                        </DataTemplate>
                    </telerik:GridViewColumn.CellTemplate>
                </telerik:GridViewColumn>
                <telerik:GridViewDataColumn Header="Indicator" DataMemberBinding="{Binding DisplayName}" IsReadOnly="True" Width="250" />
                <telerik:GridViewColumn IsReadOnly="False" Header="Log" Width="35">
                    <telerik:GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <CheckBox IsChecked="{Binding LOG, Mode=TwoWay}"/>
                        </DataTemplate>
                    </telerik:GridViewColumn.CellTemplate>
                </telerik:GridViewColumn>
                <telerik:GridViewColumn IsReadOnly="False" Header="Lag" Width="75">
                    <telerik:GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding LAG, Mode=TwoWay}"/>
                        </DataTemplate>
                    </telerik:GridViewColumn.CellTemplate>
                </telerik:GridViewColumn>
                <telerik:GridViewColumn Header="Del." Width="35">
                    <telerik:GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <telerik:RadButton Command="{Binding Delete}" CommandParameter="{Binding}" Width="27" Height="20">
                                <Image Source="/finStat.MacroVal.UI;component/Images/del_small.png"></Image>
                            </telerik:RadButton>
                        </DataTemplate>
                    </telerik:GridViewColumn.CellTemplate>
                </telerik:GridViewColumn>
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>

Here is my ViewModel
public List<Indicator> IndicatorsList
        {
            get { return Indicators.ToList(); }
        }
public bool IncludeIt
{
       get { /******Here How I get current object item (i.e. Indicator) of the row so that I can return its value *********/ }
       set {  /******Here How I get current object item (i.e. Indicator) of the row so that I set its value *********/ }
}
I am really stuck that how can I create properties for these check boxes and TextBox. Basically how can I get specific row DataItem in checkbox property so that I can return specific field from that DataItem.
Although my actual Model object is Entity Framework Model, but here is sample model for this example.
public class Indicator
{
    public bool IncludeIndicator { get; set; }
    public string Name { get; set; }
    public bool Log { get; set; }
    public double Lag { get; set; }
}

Any help please?

1 Answer, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 31 Aug 2011, 08:36 AM
Hi Muhammad Irfan,

I am sending you a sample project illustrating how you may bind the columns in the grid to the corresponding properties of your business object. Considering the calculation, you may either perform it in the RowEditEnded or if appropriate, work directly with the GridViewExpressionColumn.
Let me know if you need any further assistance.
 

Best wishes,
Maya
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
GridView
Asked by
Muhammad Irfan
Top achievements
Rank 1
Answers by
Maya
Telerik team
Share this question
or