有没有一种方法可以在不离开视图的情况下重新加载DataGrid?

时间:2019-07-09 12:25:02

标签: wpf vb.net datagrid

我有一个应用程序,其视图包含一个DataGrid。打开视图时,它会填满自己,但是我需要单击按钮进行翻译。我有一个功能转换按钮,但是,按下按钮时需要刷新DataGrid。

重新加载页面(通过调用处理load事件的方法)不会重新加载DataGrid。我没有可用的RefreshDataGrid方法(尽管如果有人对如何做有建议,我可以做一个)。我有一个subLoadReportList(),但是它不刷新DataGrid。

Private Sub wpfTimeSheetReports_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
    Try
        Dim pstrErrMsg As String = String.Empty
        If modGlobalFunctions.ftnAuthenticateUser(pstrErrMsg) = False Then
            Dim m As New WPF_CommonControlsLibrary.CustomMessageBox(gAppNameEnglish, gAppNameFrench, pstrErrMsg, pstrErrMsg, WPF_CommonControlsLibrary.CustomMessageBox.enumMsgBoxType.ErrorMsg, gCurrentEnumLanguage)
            m.ShowDialog()
            Me.Close()
            Exit Sub
        End If

        If Not (modGlobalFunctions.ftnAuthenticateUserControlAccess(Me.GetType.FullName, IsReadOnly, pstrErrMsg)) Then
            Dim m As New WPF_CommonControlsLibrary.CustomMessageBox(gAppNameEnglish, gAppNameFrench, pstrErrMsg, pstrErrMsg, WPF_CommonControlsLibrary.CustomMessageBox.enumMsgBoxType.ErrorMsg, gCurrentEnumLanguage)
            m.ShowDialog()
            Me.Close()
            Exit Sub
        End If

        subLoadReportList()
        dgDefinedReport.SelectedValue = 0

    Catch ex As Exception
        strError = ex.Message & vbCrLf & " IN: " & Me.GetType.FullName
        Throw New LegalServicesException(ex)
    Finally
        If strError.Length() > 0 Then
            modGlobalFunctions.DisplayErrorMsg(strError, strError)
            strError = String.Empty
        End If
    End Try
End Sub

Private Sub subLoadReportList()
    Try
        If CurrentLanguageSelection = enumLanguage.English Then
            dgDefinedReport.ItemsSource = ActiveReports
            dgDefinedReport.DisplayMemberPath = "Name_English"
            dgDefinedReport.SelectedValuePath = "Defined_Report_ID"
        Else
            dgDefinedReport.ItemsSource = ActiveReports
            dgDefinedReport.DisplayMemberPath = "Name_French"
            dgDefinedReport.SelectedValuePath = "Defined_Report_ID"
        End If

     Catch ex As Exception
        strError = ex.Message & vbCrLf & " IN: " & Me.GetType.FullName
        Throw New LegalServicesException(ex)
    Finally
        If strError.Length() > 0 Then
            modGlobalFunctions.DisplayErrorMsg(strError, strError)
            strError = String.Empty
        End If
    End Try
End Sub

Private Sub btnChangeLanguage_Click(sender As Object, e As RoutedEventArgs) Handles btnChangeLanguage.Click
    Try
        If CurrentLanguageSelection = enumLanguage.English Then
            CurrentLanguageSelection = enumLanguage.French
            Dim newCulture As CultureInfo = New CultureInfo("fr-CA")
            Thread.CurrentThread.CurrentCulture = newCulture
            gCurrentStrLanguage = "FR"
            wpfTimeSheetReports_Loaded(sender, e)
            subLoadReportList()

        ElseIf CurrentLanguageSelection = enumLanguage.French Then
            CurrentLanguageSelection = enumLanguage.English
            Dim newCulture As CultureInfo = New CultureInfo("en-CA")
            Thread.CurrentThread.CurrentCulture = newCulture
            gCurrentStrLanguage = "EN"
            wpfTimeSheetReports_Loaded(sender, e)
            subLoadReportList()

        End If
    Catch ex As Exception
        Throw ex
    End Try
End Sub

0 个答案:

没有答案