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

GridView prevent focus when pressing edit button

2 Answers 111 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Greg
Top achievements
Rank 1
Greg asked on 13 Dec 2013, 03:33 PM
Hello,

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.

**small edit**
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" Grid.Row="2" ValidatesOnDataErrors="None" IsReadOnly="True" ShowColumnSortIndexes="True" CanUserFreezeColumns="False" ItemsSource="{Binding PagedSource, ElementName=radDataPager}" >
                <telerik:RadGridView.Columns><br>
                    <telerik:GridViewColumn Header="Edit"><br>
                        <telerik:GridViewColumn.CellTemplate><br>
                            <DataTemplate><br>
                                <Button Content="Edit" Style="{StaticResource HyperLinkButtonStyle}"<br>
                                            Click="EditButton_Click" /><br>
                            </DataTemplate><br>
                        </telerik:GridViewColumn.CellTemplate><br>
                    </telerik:GridViewColumn><br>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Organization}" Header="Organization"/><br>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding VisitDate, StringFormat=d}" Header="Visit Date"/><br>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Location}" Header="Location"/><br>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Address}" Header="Address"/><br>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding ContactPersonName}" Header="Contact Name"/><br>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding ContactPersonEmail}" Header="Contact E-mail"/><br>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding ContactMobileNumberConcatenate}" Header="Contact Mobile Number"/><br>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding ContactHomeNumberConcatenate}" Header="Contact Home Number"/><br>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding ContactOfficeNumberConcatenate}" Header="Contact Office Number"/><br>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding ContactFaxNumberConcatenate}" Header="Contact Fax Number"/><br>
                </telerik:RadGridView.Columns><br>
            </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

2 Answers, 1 is accepted

Sort by
0
Greg
Top achievements
Rank 1
answered on 16 Dec 2013, 06:12 PM
Answering my own question here.. just in case someone runs into the same problem

***************************


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>
0
Yoan
Telerik team
answered on 17 Dec 2013, 07:49 PM
Hi Greg,

Thank you for the update. I am glad to hear you have resolved the issue. 

Regards,
Yoan
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Greg
Top achievements
Rank 1
Answers by
Greg
Top achievements
Rank 1
Yoan
Telerik team
Share this question
or