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

Command-Binding Problem for a Button inside a RadGridView

10 Answers 1099 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sternico
Top achievements
Rank 1
Sternico asked on 18 Nov 2009, 08:42 AM
Hello,
I've Problems with binding a comman for a Button inside a RadGridView-Column. I'm using the Q3 Release.

This is my XAML:
<telerik:GridViewDataColumn Header=""  UniqueName="Product.ProductID" IsReadOnly="True"  Background="{StaticResource ProductColumnsBackground}" HeaderCellStyle="{StaticResource DefaultHeaderStyle}">
  <telerik:GridViewDataColumn.CellTemplate>
    <DataTemplate>
      <Button Margin="2" Command="{Binding Path=DataContext.AddDefectCommand, ElementName=productGrid}" CommandParameter="{Binding }">
        <StackPanel Orientation="Horizontal">
          <Image RenderOptions.BitmapScalingMode="NearestNeighbor" Width="16" Height="16" Source="../Resources/Defect_16.png"/>
          <TextBlock Margin="5" Text="Neuer Mangel"/>
        </StackPanel>
      </Button>
    </DataTemplate>
  </telerik:GridViewDataColumn.CellTemplate>
</telerik:GridViewDataColumn>



"productGrid" is the name of the RadGridView.

10 Answers, 1 is accepted

Sort by
0
Michael
Top achievements
Rank 1
answered on 19 Nov 2009, 06:10 AM
Yes.

I'm also having problems with using Command in CellTemplate.

 <telerik:GridViewColumn.CellTemplate> 
                                        <DataTemplate> 
                                            <CheckBox HorizontalAlignment="Center"   
                                                      IsChecked="{Binding IsSelected}"  
                                                      Command="{Binding ElementName=rfComponentLabel,Path=DataContext.CheckRFComponentCommand}" 
                                                      CommandParameter="{Binding}"></CheckBox> 
                                        </DataTemplate> 
                                    </telerik:GridViewColumn.CellTemplate> 

rfComponentLabel is a label control inside View (XAML). This datacontext of view is already set to ViewModel.



0
Vlad
Telerik team
answered on 19 Nov 2009, 11:47 AM
Hello,

I've just tried ElementBinding in CellTemplate with MS DataGrid and got the same result. You can check the attached project for reference.

Greetings,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Sternico
Top achievements
Rank 1
answered on 19 Nov 2009, 12:37 PM
Hello,

I don't know the Microsoft DataGrid very well. Before I used the Telerik Grid I used the ListView in this way and it worked fine:

<ListView x:Name="lv1" Grid.Row="2"  ItemsSource="{Binding Data}">
  <ListView.View>
    <GridView>
      <GridViewColumn Header="Name">
        <GridViewColumn.CellTemplate>
          <DataTemplate>
            <TextBlock Text="{Binding Name}" VerticalAlignment="Center"  />
          </DataTemplate>
        </GridViewColumn.CellTemplate>
      </GridViewColumn>
                    
      <GridViewColumn Header="Action">
        <GridViewColumn.CellTemplate>
          <DataTemplate>
            <Button Command="{Binding Path=DataContext.AddDefectCommand, ElementName=lv1}" Height="20" Width="20" />
          </DataTemplate>
        </GridViewColumn.CellTemplate>
      </GridViewColumn>
    </GridView>
  </ListView.View>
</ListView>

How can I achieve this? I really nedd this functionality.
0
Michael
Top achievements
Rank 1
answered on 19 Nov 2009, 01:05 PM
Hi Vlad ,
Could you please try Command?  Both my sample and Sternico's sample are using command and we found that its not working.
0
Vlad
Telerik team
answered on 19 Nov 2009, 01:17 PM
Hi Michael,

I believe that we will get the same result with Command. Most probably this was caused (in both grids) by rows virtualization - ElementName cannot find the element in the logical tree due to missing parent at some stage.

We will try to debug this to see what we can do.

Regards,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Michael
Top achievements
Rank 1
answered on 19 Nov 2009, 02:23 PM
Thanks. It's kinda showstopper for us .. It would be great if we can get the fix as soon as we can. 
0
Vlad
Telerik team
answered on 19 Nov 2009, 03:39 PM
Hello,

I've attached an example project demonstrating how to achieve your goal using RelativeSource FindAncestor for the Binding instead ElementName.

Sincerely yours,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Michael
Top achievements
Rank 1
answered on 19 Nov 2009, 04:24 PM
Great!!!

Thanks a lot..  You saved my day.  Please help me to solve this issue as well http://www.telerik.com/account/support-tickets/view-ticket.aspx?threadid=260293

I'm thinking to use CRUD Datagrid in one of views. RadGridView doesn't any option like AddNewRow=True so I'm thinking to add new row on button click. But what happened is that RadGridView doesn't show new row even ObserverableCollection which is binded to Grid has changes.

Thanks again.
0
Michael
Top achievements
Rank 1
answered on 03 Dec 2009, 04:36 AM
As you suggested, I'm using RelativeSource Binding below .  But it doesn't work if this binding is in nested grid. How can I use it in child grid?

<telerik:GridViewColumn.CellTemplate>
                                <DataTemplate>
                                        <CheckBox HorizontalAlignment="Center"  
                                                      IsChecked="{Binding IsSelected}" 
                                                      Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:GridViewDataControl}},Path=DataContext.CheckPaymentMilestoneCommand}"
                                                     />
                                    </DataTemplate>
                            </telerik:GridViewColumn.CellTemplate>
0
Vlad
Telerik team
answered on 03 Dec 2009, 07:01 AM
Hi Michael,

You can specify ancestor level in the logical tree for such bindings. Please check this article for more info:
http://msdn.microsoft.com/en-us/library/ms743599.aspx

Regards,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Sternico
Top achievements
Rank 1
Answers by
Michael
Top achievements
Rank 1
Vlad
Telerik team
Sternico
Top achievements
Rank 1
Share this question
or