WPF Datagrid Get Selected Cell Value

前端 未结 12 2055
遇见更好的自我
遇见更好的自我 2020-11-30 08:47

I want to get value for selected cell in datagrid , please anyone tell how to do this. i used SelectedCell changed event , how can i do that?

dataGrid1.Curre         


        
12条回答
  •  醉梦人生
    2020-11-30 09:51

    I struggled with this one for a long time! (Using VB.NET) Basically you get the row index and column index of the selected cell, and then use that to access the value.

    Private Sub LineListDataGrid_SelectedCellsChanged(sender As Object, e As SelectedCellsChangedEventArgs) Handles LineListDataGrid.SelectedCellsChanged
    
        Dim colInd As Integer = LineListDataGrid.CurrentCell.Column.DisplayIndex
    
        Dim rowInd As Integer = LineListDataGrid.Items.IndexOf(LineListDataGrid.CurrentItem)
    
        Dim item As String
    
        Try
            item = LLDB.LineList.Rows(rowInd)(colInd)
        Catch
            Exit Sub
        End Try
    
    End Sub
    

    End Class

提交回复
热议问题