Home WPF DataGrid - How detect if full row is selected?
Reply: 0

WPF DataGrid - How detect if full row is selected?

user1337
1#
user1337 Published in April 22, 2018, 12:59 am

I have DataGrid in my WPF application, and I want to run a function in the SelectedCellsChanged event, but only if the row is not fully selected, which happens if the user clicks at the header of the row.

My table has only one column.

I've tried the following code and always the value of rowContainer.IsSelected is false.

How can I do this?

Private Sub DataGridEx_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles Me.SelectionChanged

    If SelectedCells.Count <> 1 Then
        Exit Sub
    End If

    If Not SelectedCells.First.Item.ToString.Contains("NewItemPlaceholder") Then

            Me.TheDispatcher.BeginInvoke(
                Sub()
                    Dim cell = SelectedCells.First
                    Dim index = Items.IndexOf(cell.Item) + 1
                    Dim rowContainer As DataGridRow = ItemContainerGenerator.ContainerFromIndex(index)

                    If rowContainer IsNot Nothing Then
                        If Not rowContainer.IsSelected Then
                            ' run a function here
                        End If
                    End If
                End Sub,
                DispatcherPriority.Input)

     End If

End Sub
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.304996 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO