Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1375
focus on textbox when editing
posted

I am using a templated column for editing.  i have multiple text boxes in a Grid in the EditorTemplate.

I am trying so set Focus when going in to edit mode using:

Private Sub dgPO_CellEnteredEditMode(ByVal sender As Object, _
                                         ByVal e As Infragistics.Silverlight.EditingCellEventArgs) Handles dgPO.CellEnteredEditMode

        If e.Cell.Column.Key = "Notes" Then

           Dim grd As Grid = e.Editor

            Dim tb As TextBox = grd.Children(0)             'used to be 1 before change
            tb.Focus()
        End If

is there any reason this shouldnt work?  am i doing something wrong??  is it possible?

Parents
No Data
Reply
  • 40030
    Verified Answer
    Offline posted

    Hi, 

    So, a control can only be focused after its been loaded.  In the CellEnteredEdit mode, the content of the cell hasn't finished loading, which is why if you check the returned value of the Focus() method, you'd see that it returned false. 

    However, you can simply solve the problem, by hooking into the loaded event of the control you want to have focus:

    <ig:TemplateColumn.EditorTemplate>

                                        <DataTemplate>

                                              <StackPanel>

                                                    <TextBox Loaded="TextBox_Loaded" Text="{Binding Title, Mode=TwoWay}"></TextBox>

                                                    <TextBox Text="{Binding Type, Mode=TwoWay}"></TextBox>

                                              </StackPanel>

                                        </DataTemplate>

                                  </ig:TemplateColumn.EditorTemplate>

    private void TextBox_Loaded(object sender, RoutedEventArgs e)

                {

                      ((Control)sender).Focus();

                }

    -SteveZ

Children