Question

I have a radgridview where one column is an edit button which redirects the page and the rest of the columns are databound from my source.

My problem is that to be able to press the edit button on a specific row for the first time the user basically has to press it twice because the first click for some reason focuses the entire gridview first into view.

This only happens when the entire gridview does not fit into the view so I am guessing it tries to automatically fit itself as best as it can before it lets me press the edit button - it does not happen if i press on any of the static uneditable fields - only on the edit button

<telerik:RadGridView Name="radGridView" VerticalAlignment="Top"
                     AutoGenerateColumns="False" 
                     ValidatesOnDataErrors="None" IsReadOnly="True"
                     ShowColumnSortIndexes="True" 
                     CanUserFreezeColumns="False" 
                     ItemsSource="{Binding PagedSource, ElementName=radDataPager}" >

    <telerik:RadGridView.Columns>

        <telerik:GridViewColumn Header="Edit">
            <telerik:GridViewColumn.CellTemplate>
                <DataTemplate>
                    <Button Content="Edit" Style="{StaticResource HyperLinkButtonStyle}"
                            Click="EditButton_Click" />
                </DataTemplate>
            </telerik:GridViewColumn.CellTemplate>
        </telerik:GridViewColumn>

        <telerik:GridViewDataColumn DataMemberBinding="{Binding Organization}" Header="Organization"/>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding VisitDate, StringFormat=d}" Header="Visit Date"/>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding Location}" Header="Location"/>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding Address}" Header="Address"/>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding ContactPersonName}" Header="Contact Name"/>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding ContactPersonEmail}" Header="Contact E-mail"/>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding ContactMobileNumberConcatenate}" Header="Contact Mobile Number"/>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding ContactHomeNumberConcatenate}" Header="Contact Home Number"/>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding ContactOfficeNumberConcatenate}" Header="Contact Office Number"/>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding ContactFaxNumberConcatenate}" Header="Contact Fax Number"/>

    </telerik:RadGridView.Columns>

</telerik:RadGridView>

Is there a way to prevent this focus from happening when I press on an edit button inside the grid? or am I missing something else

Was it helpful?

Solution

For some reason the problem was that I was using a button in the datatemplate as

<Button Content="Edit" Style="{StaticResource HyperLinkButtonStyle}" Click="EditButton_Click" />

Something about the Button was making the gridview have to first focus itself into the view before a subsequent click on that button would fire the click event in the cases where it was not fully fitting on the screen..

I ended up doing the workaround of simply using a telerik label and giving it a MouseLeftButtonDown event

<telerik:Label Content="Edit" TouchDown="EditButton_Click" MouseLeftButtonDown="EditButton_Click" Style="{StaticResource HyperLinkStyle}"/>

Pretty sure you should be able to use a regular label as well

The HyperLinkStyle is just a style that makes the label underlined and gives it a color and hover state

<UserControl.Resources>
        <Style x:Key='HyperLinkStyle' TargetType='telerik:Label'>
            <Setter Property='Template'>
                <Setter.Value>
                    <ControlTemplate  TargetType='telerik:Label'>
                        <TextBlock  TextDecorations='Underline'>
                             <ContentPresenter TextBlock.FontFamily='Segoe UI' TextBlock.FontSize='13'/>
                        </TextBlock>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property='Foreground' Value='#195AE0' />
            <Style.Triggers>
                <Trigger Property='IsMouseOver' Value='true'>
                    <Setter   Property='Foreground'    Value='Red' />
                    <Setter Property='Cursor' Value='Hand' />
                </Trigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>

OTHER TIPS

You can also change appropriate property for button if it is not important for you:

<Button Focusable="False" Content="Edit" Style="{StaticResource HyperLinkButtonStyle}" Click="EditButton_Click"/>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top