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

Button into a GridViewDataColumn

3 Answers 205 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Nick
Top achievements
Rank 1
Nick asked on 25 Jan 2010, 02:56 PM

Hello everybody,
I am using  RadControls for WPF Q3 2009 SP2, and the version of the Telerik.Windows.Controls.GridView.dll is 2009.3.1314.35

In a gridview I had to insert a button with an image using the following XAML code;

<telerik:RadGridView x:Name="radGridInvoiceDetails" ShowGroupPanel="False" AutoGenerateColumns="False" Height="280" Width="920" HorizontalAlignment="Left" ScrollMode="RealTime" ItemsSource="" >
    <telerik:RadGridView.Columns> 
        <telerik:GridViewDataColumn Header="ProductType" DataMemberBinding="{Binding ProductTypeDescription}" IsReadOnly="True" IsFilterable="False" HeaderTextAlignment="Center" Width="Auto" IsVisible="False"/>
        <telerik:GridViewDataColumn Header="Prodotto" DataMemberBinding="{Binding ProductDescription}" IsReadOnly="True" IsFilterable="False" HeaderTextAlignment="Center" Width="Auto" IsVisible="False"/>
        <telerik:GridViewDataColumn Header="Numero" DataMemberBinding="{Binding BillNumberString}" IsReadOnly="True" IsFilterable="False" HeaderTextAlignment="Center" Width="Auto" TextAlignment="Right"/>
        <telerik:GridViewDataColumn Header="Data" DataMemberBinding="{Binding BillDate}" IsReadOnly="True" IsFilterable="False" HeaderTextAlignment="Center" Width="Auto" DataFormatString="{}{0:dd/MM/yyyy}"/>
        <telerik:GridViewDataColumn Header="Qta" DataMemberBinding="{Binding ProductQuantity}" IsReadOnly="True" IsFilterable="False" HeaderTextAlignment="Center" Width="Auto" DataFormatString="{}{0:N2}" TextAlignment="Right"/>
        <telerik:GridViewDataColumn Header="Prz.Uni" DataMemberBinding="{Binding ProductFee}" IsReadOnly="True" IsFilterable="False" HeaderTextAlignment="Center" Width="Auto" DataFormatString="{}{0:N2}" TextAlignment="Right"/>
        <telerik:GridViewDataColumn Header="Tot.Prod" DataMemberBinding="{Binding ProductTotal}" IsReadOnly="True" IsFilterable="False" HeaderTextAlignment="Center" Width="Auto" DataFormatString="{}{0:N2}" TextAlignment="Right"/>
        <telerik:GridViewDataColumn Header="Scontato" DataMemberBinding="{Binding ProductDiscountedTotal}" IsReadOnly="True" IsFilterable="False" HeaderTextAlignment="Center" Width="Auto" DataFormatString="{}{0:N2}" TextAlignment="Right"/>
        <telerik:GridViewDataColumn Header="Trasporto" DataMemberBinding="{Binding TransportTotal}" IsReadOnly="True" IsFilterable="False" HeaderTextAlignment="Center" Width="Auto" DataFormatString="{}{0:N2}" TextAlignment="Right"/>
        <telerik:GridViewDataColumn Header="Scontato" DataMemberBinding="{Binding TransportDiscountedTotal}" IsReadOnly="True" IsFilterable="False" HeaderTextAlignment="Center" Width="Auto" DataFormatString="{}{0:N2}" TextAlignment="Right"/>
        <telerik:GridViewDataColumn Header="Sconto totale" DataMemberBinding="{Binding TotalDiscountAmount}" IsReadOnly="True" IsFilterable="False" HeaderTextAlignment="Center" Width="Auto" DataFormatString="{}{0:N2}" TextAlignment="Right"/>
        <telerik:GridViewDataColumn Header="Imponibile" DataMemberBinding="{Binding TotalBill}" IsReadOnly="True" IsFilterable="False" HeaderTextAlignment="Center" Width="Auto" DataFormatString="{}{0:N2}" TextAlignment="Right"/>
        <telerik:GridViewDataColumn Header="IVA" DataMemberBinding="{Binding VATString}" IsReadOnly="True" IsFilterable="False" HeaderTextAlignment="Center" Width="Auto" TextAlignment="Right"/>
        <telerik:GridViewDataColumn Header="Totale" DataMemberBinding="{Binding TotalVAT}" IsReadOnly="True" IsFilterable="False" HeaderTextAlignment="Center" Width="Auto" DataFormatString="{}{0:N2}" TextAlignment="Right"/>
        <telerik:GridViewDataColumn x:Name="columnView" IsFilterable="False" IsSortable="False" Width="40">
            <telerik:GridViewColumn.CellTemplate>
                <DataTemplate>
                    <Button x:Name="buttonView" Click="buttonView_Click" Background="White" BorderBrush="White">
                        <Image Height="20" Width="20" Source="/Raise.FarinaEzio.SIB.Client.Management.GUI.BusinessManagement.Controls;component/Images/Edit.png" />
                        <Button.ToolTip>
                            <StackPanel Orientation="Horizontal">
                               <Image Source="/Raise.FarinaEzio.SIB.Client.Management.GUI.BusinessManagement.Controls;component/Images/Edit.png" />  
                              <Label Content="Visualizza la bolla"/>
                          </StackPanel>
                       </Button.ToolTip>
                   </Button>
                </DataTemplate>
            </telerik:GridViewColumn.CellTemplate>
        </telerik:GridViewDataColumn>
    </telerik:RadGridView.Columns>
</telerik:RadGridView>

In the code behind I had to add some group and some sum functions using code like the following

GroupDescriptor descriptor = new Telerik.Windows.Data.GroupDescriptor();
 
descriptor.Member = "ProductTypeDescription";
descriptor.SortDirection = ListSortDirection.Ascending;
radGridInvoiceDetails.GroupDescriptors.Add(descriptor);
descriptor = new Telerik.Windows.Data.GroupDescriptor(); 
descriptor.Member = "ProductDescription";
descriptor.SortDirection = ListSortDirection.Ascending;
var sumFunction = new Telerik.Windows.Data.SumFunction();
sumFunction.ResultFormatString = "{0:N2}";
sumFunction.SourceField = "ProductQuantity";
sumFunction.Caption = "Totale Quantit";
descriptor.AggregateFunctions.Add(sumFunction);
sumFunction = new Telerik.Windows.Data.SumFunction();
sumFunction.ResultFormatString = "{0:N2}";
sumFunction.SourceField = "TotalBill";
sumFunction.Caption = "Totale Imponibile";
descriptor.AggregateFunctions.Add(sumFunction);
sumFunction = new Telerik.Windows.Data.SumFunction();
sumFunction.ResultFormatString = "{0:N2}";
sumFunction.SourceField = "TotalVAT";
sumFunction.Caption = "Totale Con IVA";
descriptor.AggregateFunctions.Add(sumFunction);
radGridInvoiceDetails.GroupDescriptors.Add(descriptor);

Every grouping and sum functions work perfectly.
My problem is the button inserted in datatemplate.
The first time the grid is filled up all the buttons are clickable and when they are clicked evrything works very fine.
Starting from the second time none of the buttons are clickable anymore. The look and feel of the problem is that after the click the button is shown as selected but the typical "click behaviour" of the button disappeares and no Click event is trapped.
Insisting to the click of the button the image disappears and you see a small text box that takes the focus.
I have already used buttons inserted into a datatemplate but I have never seen this strange behaviour.
The first thought I've had is that the problem may be due to the groups I have add, that's because in the other grids no groups were added.

Thank you very much in advance for you help.

Nick

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 26 Jan 2010, 12:42 PM
Hello Nick,

Please set IsReadOnly for this column to True to avoid this.

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
Nick
Top achievements
Rank 1
answered on 01 Feb 2010, 10:33 AM
Hello Vlad.
Thanks for your suggestion.
I have followed it but there is still a strange phenomenon:
The first click is accepted, but subsequent clicks on the button not.
It almost seems that the button becomes readonly.

What's the problem?

Thank you in advance

Nick

0
Vlad
Telerik team
answered on 03 Feb 2010, 02:46 PM
Hi Nick,

I've tried to reproduce this using SP2 however everything worked fine on my end - please check the attached example project for reference.

Kind regards,
Vlad
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Tags
GridView
Asked by
Nick
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Nick
Top achievements
Rank 1
Share this question
or