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

[Solved] Button and Context Menu

1 Answer 140 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Voss Grose
Top achievements
Rank 1
Voss Grose asked on 27 Jul 2009, 03:45 PM
I've come across some posts that are close to explaining what I'm trying to do, but not exactly.

I have a GridView (grouped) with one column that is a button.
I want to be able to "SetContextMenu" on the click event of the button, but can't figure out how to do it.

If there is a better way to approach this please let me know. I can catch the Button Click event so if there is way to open the ContextMenu in the btnActions_Click that would be easy enough as well.
Thanks,
Voss.

XAML:
    <grid:RadGridView x:Name="RadGridView1" ShowGroupPanel="False" CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserSortColumns="False" IsFilteringAllowed="False" MultipleSelect="False" RowIndicatorVisibility="Collapsed" IsReadOnly="True" AutoGenerateColumns="False" ColumnsWidthMode="None" CanUserFreezeColumns="False" Width="400" RowLoaded="RadGridView1_RowLoaded" RowStyle="{StaticResource RowStyle}" AlternateRowStyle="{StaticResource AlternateRowStyle}" GroupRowStyle="{StaticResource GroupRowStyle}" UseAlternateRowStyle="True">
        <grid:RadGridView.GroupDescriptors>
            <data:GroupDescriptor Member="Time">
                <data:GroupDescriptor.AggregateFunctions>
                    <data:CountFunction Caption="COUNT: " />
                </data:GroupDescriptor.AggregateFunctions>
            </data:GroupDescriptor>
        </grid:RadGridView.GroupDescriptors>
        <grid:RadGridView.Columns>
            <grid:GridViewDataColumn HeaderText="TBL" UniqueName="Reservation.TableCode" Width="37" />
            <grid:GridViewDataColumn HeaderText="CD" UniqueName="Reservation.Guest.Code" Width="25" TextAlignment="Center" />
            <grid:GridViewDataColumn HeaderText="NAME" UniqueName="Reservation.Guest.FullName" Width="150" />
            <grid:GridViewDataColumn HeaderText="#" UniqueName="Size" Width="28" TextAlignment="Center" />
            <grid:GridViewDataColumn HeaderText="T" UniqueName="Reservation.Cover" Width="28" TextAlignment="Center" />
            <grid:GridViewDataColumn HeaderText="ARR" UniqueName="Reservation.ArrivedTime" Width="62" DataFormatString="{}{0:t}" />
            <grid:GridViewDataColumn HeaderText="" DataMemberBinding="{Binding Id}" Width="30">
                <grid:GridViewDataColumn.CellTemplate>
                    <DataTemplate>
                        <Button x:Name="btnActions" Height="20" Width="20" BorderThickness="0">
                            <Image Source="images/TimeSlotAction.png" Height="15" Width="15" />
                        </Button>
                    </DataTemplate>
                </grid:GridViewDataColumn.CellTemplate>
            </grid:GridViewDataColumn>
        </grid:RadGridView.Columns>
    </grid:RadGridView>


 <telerikNavigation:RadContextMenu.ContextMenu>
        <telerikNavigation:RadContextMenu x:Name="contextMenu">
            <telerikNavigation:RadMenuItem Header="Set Vista as Background 1" />
            <telerikNavigation:RadMenuItem Header="Set Vista as Background 2" />
        </telerikNavigation:RadContextMenu>
    </telerikNavigation:RadContextMenu.ContextMenu>

1 Answer, 1 is accepted

Sort by
0
Accepted
Hristo
Telerik team
answered on 28 Jul 2009, 06:32 AM
Hi Voss Grose,

You can attach the contextMenu to the button like this: (I'm pasting only the changes, everything else is the same):
<grid:GridViewDataColumn.CellTemplate> 
   <DataTemplate> 
      <Button x:Name="btnActions" Height="20" Width="20" BorderThickness="0">  
         <telerikNavigation:RadContextMenu.ContextMenu> 
            <telerikNavigation:RadContextMenu EventName="Click">  
               <telerikNavigation:RadMenuItem Header="Set Vista as Background 1" /> 
               <telerikNavigation:RadMenuItem Header="Set Vista as Background 2" /> 
            </telerikNavigation:RadContextMenu> 
         </telerikNavigation:RadContextMenu.ContextMenu> 
         <Image Source="images/TimeSlotAction.png" Height="15" Width="15" /> 
      </Button> 
   </DataTemplate> 
</grid:GridViewDataColumn.CellTemplate> 

Let us know if you need more help.

Regards,
Hristo
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Voss Grose
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Share this question
or