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

Button Column

2 Answers 82 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 05 May 2011, 12:37 PM
Hi and as always, thanks ...

In a RadGrid I've created a button column using a DataTemplate (seperate file for reuse). In this particular grid I'm trying to have it all readonly while maintaining the buttons click ability immediately on load (i.e. no need for the user to double click a row to enable).  What I'm finding (probably because of a code issue on my part) is that I can only click the button if I double click a cell, leave it and return.  Can you please point out where I'm missing something.

The Grid looks like:
<telerik:RadGridView x:Name="dg_tblSOLines" 
                                         telerik:StyleManager.Theme="Expression_Dark" Height="Auto" Width="Auto" ShowGroupPanel="False"
                                         AutoGenerateColumns="False" ShowInsertRow="False" Background="#FFA4A6A9" 
                                         telerikDragDrop:RadDragAndDropManager.AllowDrop="True" ShowColumnFooters="True" >
                        <telerik:RadGridView.Columns>
                            <telerik:GridViewDataColumn IsFilterable="False" CellTemplate="{StaticResource EditDeleteButtonsTemplate}" />
                            <telerik:GridViewDataColumn UniqueName="dc_quantitySO" Header="Quantity" IsReadOnly="True"
                                                        DataMemberBinding="{Binding Path=quantity}" IsFilterable="False" IsGroupable="False" IsReorderable="False" />
                                    ............
                             </telerik:RadGridView.Columns>
                    </telerik:RadGridView>

The button template looks like:
<Grid x:Name="LayoutRoot" >
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
  
        <Button x:Name="btn_editSOLine" HorizontalAlignment="Center" VerticalAlignment="Center" Width="Auto" Height="Auto" Style="{StaticResource OpacityButton}">
            <Image Source="/RoasterWerks;component/Images/edit-4.png" Stretch="None"/>
        </Button>
        <Button x:Name="btn_delSOLine" HorizontalAlignment="Center" VerticalAlignment="Center" Width="Auto" Height="Auto" Grid.Column="1" 
                Style="{StaticResource OpacityButton}" Command="{Binding deleteCommand, Source={StaticResource TelerikGridViewCommands}}" 
                CommandParameter="{Binding SelectedItem, Source={StaticResource RoasterWerksDomainContext}}">
                <Image Source="/RoasterWerks;component/Images/edit-delete-5.png" Stretch="None" />
         </Button>
  
    </Grid>

At this point I'm focusing on the delete button (btn_delSOLine). 
On initial load the edit button is clickable but the delete button is not. As you can see above there is currently no binding to commands in respect to the edit button.

If I double click the cell it enters edit mode (buttons are no longer visible).  If I click out of the cell and click to a different row, the buttons become visible and the btn_delSOLine also becomes clickable.  The edit button (btn_editSOLine) remains clickable at all times.

The command seems straight forward and works without issue after the button becomes clickable.
public class TelerikGridViewCommands
   {
       public ICommand deleteCommand
       {
           get
           {
               return RadGridViewCommands.Delete;
           }
       }
   }

2 Answers, 1 is accepted

Sort by
0
Accepted
Vanya Pavlova
Telerik team
answered on 05 May 2011, 12:51 PM
Hello Mark,

 
If you take a look at our Commands demo, you may see that the Delete button in each column is enabled. The main reason is the fact that the commands initialization is done before the InitializeComponent method:

public Example()
{
            ICommand deleteCommand = RadGridViewCommands.Delete;
            ICommand beginInsertCommand = RadGridViewCommands.BeginInsert;
            ICommand cancelRowEditCommand = RadGridViewCommands.CancelRowEdit;
            ICommand commitEditCommand = RadGridViewCommands.CommitEdit;
 
       InitializeComponent();
}


If you do the same in our project you will be able to see the enabled buttons in this column. 
You may read more about Commands in our online documentation.


Best wishes,
Vanya Pavlova
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Mark
Top achievements
Rank 1
answered on 05 May 2011, 01:00 PM
Hi Vanya,

Thanks very much.  I was hoping to approach this is a bit more of a reusable / loosely coupled manner but that seems to cause my grief.  I had both the DataTemplate and well as seperate Commands.cs as per a different Telerik example.

Mark
Tags
GridView
Asked by
Mark
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Mark
Top achievements
Rank 1
Share this question
or