Home Forums WPF controls Xceed DataGrid for WPF Focus on CardView Cell

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #24733 |

    In C#, how do I force the focus to a specific DataCell?

    Imported from legacy forums. Posted by Brian (had 578 views)

    User (Old forums)
    Member
    Post count: 23064

    Does DataCell.Focus() work for you?

    Imported from legacy forums. Posted by nat (had 313 views)

    User (Old forums)
    Member
    Post count: 23064

    I’m not sure how to get a reference to the DataCell. It’s defined in a ControlTemplate.

    Imported from legacy forums. Posted by Brian (had 293 views)

    User (Old forums)
    Member
    Post count: 23064

    Which cell do you want to focus?

    Imported from legacy forums. Posted by nat (had 363 views)

    User (Old forums)
    Member
    Post count: 23064

    The field name is Leadsource. The DataCell is definted in Here’s the datagrid:

    <xcdg:DataGridControl x:Name=”PacketGrid” CellEditorDisplayConditions=”MouseOverCell”
    EditTriggers=”BeginEditCommand,ActivationGesture”
    ItemScrollingBehavior=”Immediate” AutoCreateColumns=”True”
    ItemsSource=”{Binding Source={StaticResource searchDataView}, Path=View}”
    HorizontalAlignment=”Stretch” VerticalAlignment=”Stretch” FontSize=”12″
    Background=”gray”>
    <!– Sets up vertical scrolling –>
    <xcdg:DataGridControl.Resources>
    <Style TargetType=”{x:Type xcdg:CardViewScrollViewer}”>
    <Setter Property=”HorizontalScrollBarVisibility” Value=”Disabled” />
    </Style>
    </xcdg:DataGridControl.Resources>
    <!– Sets up vertical scrolling –>
    <xcdg:DataGridControl.View >
    <xcdg:CompactCardView Theme=”{DynamicResource defaultTheme}” HideEmptyCells=”False”>
    <xcdg:CompactCardView.FixedHeaders>
    <xcdg:ClearHeadersFooters/>
    </xcdg:CompactCardView.FixedHeaders>
    </xcdg:CompactCardView>
    </xcdg:DataGridControl.View>
    <xcdg:DataGridControl.ItemsPanel>
    <ItemsPanelTemplate>
    <xcdg:VirtualizingStackPanel Orientation=”Vertical” />
    </ItemsPanelTemplate>
    </xcdg:DataGridControl.ItemsPanel>

    <!– Map column names to user friendly ones–>
    <xcdg:DataGridControl.Columns >
    <xcdg:Column FieldName=”HeaderOrg” DisplayMemberBinding=”{Binding Path=Org,Mode=TwoWay}”/>
    <xcdg:Column FieldName=”HeaderCity” DisplayMemberBinding=”{Binding Path=City,Mode=TwoWay}”/>
    <xcdg:Column FieldName=”HeaderState” DisplayMemberBinding=”{Binding Path=State,Mode=TwoWay}”/>
    <xcdg:Column FieldName=”Status” CellEditor=”{StaticResource statusEditor}” />
    <xcdg:Column FieldName=”Requested” Title=”Received” />
    <xcdg:Column FieldName=”Leadsource” Title=”Lead” />
    <xcdg:Column FieldName=”Sendpk” Title=”Received” />
    <xcdg:Column FieldName=”Posters” Title=”Send Posters” />
    <xcdg:Column FieldName=”Salesheets” Title=”Sales Sheets” />
    <xcdg:Column FieldName=”Shipmethod” Title=”Ship Method” />
    <xcdg:Column FieldName=”Shipped” Title=”Shipped” />
    <xcdg:Column FieldName=”Addverified” Title=”Verified” />
    </xcdg:DataGridControl.Columns>
    </xcdg:DataGridControl>

    The ControlTemplate has this buried in it:

    <xcdg:DataCell VerticalAlignment=”Center” FieldName=”Leadsource” Grid.Row=”1″/>

    Imported from legacy forums. Posted by Brian (had 317 views)

    User (Old forums)
    Member
    Post count: 23064

    Which row though?

    Imported from legacy forums. Posted by nat (had 260 views)

    User (Old forums)
    Member
    Post count: 23064

    The selected one. The Focus goes at the end of this code:

    FundPacket packet = new FundPacket();
    this.Packets.Add(packet);
    this.PacketGrid.BringItemIntoView(packet);
    this.PacketGrid.Focus();
    // Set the focus to the leadsource so the user can start typing.

    Imported from legacy forums. Posted by Brian (had 258 views)

    User (Old forums)
    Member
    Post count: 23064

    DataRow row = this.PacketGrid.ItemContainerGenerator.ContainerFromItem(packet) as DataRow;
    row.Cells[“LeadSource”].Focus();

    Imported from legacy forums. Posted by nat (had 512 views)

    User (Old forums)
    Member
    Post count: 23064

    ItemContainerGenerator is depreciated. Error says to use GetContainerFromItem(). I do that and it returns null.

    My datasource is a DataGridCollectionViewSource. Does that effect the result?

    Imported from legacy forums. Posted by Brian (had 357 views)

    User (Old forums)
    Member
    Post count: 23064

    It should matter. That should work. At least it works for me

    Imported from legacy forums. Posted by nat (had 291 views)

    User (Old forums)
    Member
    Post count: 23064

    This works:

    // Make sure the object is visible in the grid.
    this.PacketGrid.CurrentItem = packet;
    this.PacketGrid.CurrentColumn = this.PacketGrid.Columns[“Leadsource”];
    this.PacketGrid.Focus();

    Imported from legacy forums. Posted by Brian (had 7319 views)

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.