synergetic
synergetic

Reputation: 8026

silverlight datagrid multicontrol TemplateColumn TabIndex issue

In SL4 DataGrid I have the following multicontrol column:

<sdk:DataGridTemplateColumn Header="Address Line1&#x0a;Address Line 2" MinWidth="200">
  <sdk:DataGridTemplateColumn.CellTemplate>
    <DataTemplate>
      <StackPanel>
        <TextBlock Text="{Binding Path=Address1}"/>
        <TextBlock Text="{Binding Path=Address2}"/>
      </StackPanel>
    </DataTemplate>
  </sdk:DataGridTemplateColumn.CellTemplate>
  <sdk:DataGridTemplateColumn.CellEditingTemplate>
    <DataTemplate>
      <StackPanel>
        <TextBox Background="Transparent" BorderThickness="0" 
                 TabIndex="0"
                 Text="{Binding Path=Address1, Mode=TwoWay}"/>
        <TextBox Background="Transparent" BorderThickness="0" 
                 TabIndex="1"
                 Text="{Binding Path=Address2, Mode=TwoWay}"/>
      </StackPanel>
    </DataTemplate>
  </sdk:DataGridTemplateColumn.CellEditingTemplate>
</sdk:DataGridTemplateColumn>

In edit mode pressing Tab key while at address1 moves focus to next DataGrid column but not to address2 textbox. If I delete CellTemplate and CellEditingTemplate to be CellTemplate instead, then TabIndex works as expected, however, current column stay the same, so if datagrid has many columns, some of which are hidden, then auto scrolling doesn't occur. What should I do to solve this problem?

Upvotes: 1

Views: 792

Answers (2)

thomas.st
thomas.st

Reputation: 413

A little bit late, but i found a workaround for this problem.

Just add a KeyDown EventHandler to your CustomControl:

private void address1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.Key.Equals(Key.Tab) && address2.IsEnabled)
    {
        address2.Focus();
        e.Handled = true;
    }
}

Upvotes: 1

synergetic
synergetic

Reputation: 8026

Probably, having multiple controls inside datagrid cell is bad idea. If multiple controls needs to be inside cell, then better way seems to be to create custom composite control and place it inside cell.

Upvotes: 0

Related Questions