Home Forums WPF controls Xceed DataGrid for WPF Programatically selecting a row

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

    I am trying to programmatically select the first row in the grid any time the DataContext is changed using the SelectedIndex property. I am setting SelectedIndex = 0, but the row isn’t being selected. Stepping through the code in a debugger does not allow me to change the value either.

    Is there another way to select a row?

    Thanks,

    Scott.

    Imported from legacy forums. Posted by Scott (had 7619 views)

    Xceed Support
    Member
    Post count: 5658

    We are currently aware of the situation with SelectedIndex, we are going to fix this issue in the next release.

    In the mean time, you could use the SelectedItem property to select the first item in the collection:

    <code>
    this.ActionTestDataGrid.SelectedItem = this.ActionTestDataGrid.Items[0];
    </code>

    Imported from legacy forums. Posted by Marcus [Xceed] (had 581 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks. I have used the work around you presented above and everything works correctly.

    Imported from legacy forums. Posted by Scott (had 367 views)

    User (Old forums)
    Member
    Post count: 23064

    This does highlight the first row, but it isn’t giving me the same effect as selecting the row with the mouse or keyboard. When the row is selected, I am populating some fields in a footer. This works correctly when selecting with the mouse, but when the data is first displayed, the footer isn’t populated even though the row is selected.

    From observation, it would appear that an event isn’t being fired when the row is selected…but that’s a guess.

    Thanks,

    Scott.

    Imported from legacy forums. Posted by Scott (had 373 views)

    Xceed Support
    Member
    Post count: 5658

    Can you give me some additional information on how you handle the selection and how populate your footer?

    Imported from legacy forums. Posted by Marcus [Xceed] (had 402 views)

    User (Old forums)
    Member
    Post count: 23064

    Sure. The DataTemplate for the footer looks like this:

    <Grid Style=”{StaticResource FooterGrid}”>
    <Grid.ColumnDefinitions>
    <ColumnDefinition Width=”Auto”/>
    <ColumnDefinition Width=”Auto”/>
    <ColumnDefinition Width=”Auto”/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
    <RowDefinition Height=”Auto”/>
    <RowDefinition Height=”Auto”/>
    </Grid.RowDefinitions>

    <TextBlock Grid.Column=”1″
    Grid.Row=”0″
    Text=”{Binding Path=CurrentItem.Name, ElementName=ActionTestDataGrid}”
    Margin=”3,3,3,3″/>
    <TextBlock Grid.Column=”1″
    Grid.Row=”1″
    Text=”Primary Contact”
    Margin=”3,0,3,3″/>

    <TextBlock Grid.Column=”2″
    Grid.Row=”0″
    Text=”Primary Address:”
    Margin=”3,3,3,3″/>
    <TextBlock Grid.Column=”3″
    Grid.Row=”0″
    Text=”{Binding Path=Addresses/City}”
    Margin=”3,3,3,3″/>
    </Grid>

    I don’t do anything special for the selection and rely on the data binding to keep everything synchronized.

    Looking at the DataTemplate above, could this be a case where SelectedItem and CurrentItem are not the same?

    Imported from legacy forums. Posted by Scott (had 397 views)

    User (Old forums)
    Member
    Post count: 23064

    Following up my own post…

    I added the following line:

    this.ActionTestDataGrid.CurrentItem = this.ActionTestDataGrid.SelectedItem;

    right after I set the SelectedItem property and everything appears to be working.

    This does lead me to believe that CurrentItem and SelectedItem do not always point to the same thing.

    Imported from legacy forums. Posted by Scott (had 354 views)

    Xceed Support
    Member
    Post count: 5658

    You are right…

    The current item can difer from the selected item.

    This is particularily visible when trying to perform multiple selections while the DataGridControl is in “Extended” SelectionMode…

    You can see this by navigating from row to row using arrow keys while holding the CTRL key. You can select/deselect rows using the Space key.

    The CurrentItem will change along with the focused Row/Cell while the SelectedItem will remain the item that was selected last.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 788 views)

    User (Old forums)
    Member
    Post count: 23064

    That makes perfect sense. I am using the “Simple” selection mode for this particular grid, so I guess i assumed that they would stay in sync. Setting the CurrentItem at the same time I set the SelectedItem is perfectly acceptable, so I will continue doing that.

    Thanks,

    Scott.

    Imported from legacy forums. Posted by Scott (had 615 views)

    User (Old forums)
    Member
    Post count: 23064

    SelectedIndex: This bug has been fixed in the latest release (Package v3.0.7113.09060, DataGrid assemblies v1.0.7113.3050), which has just been posted here:

    http://download3.xceedsoft.com/Packages/3.0.7113.09060/XceedComponents.exe

    The website has not yet been updated (release notes, update center, etc), but it will be soon.

    Imported from legacy forums. Posted by Pascal (had 8496 views)

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