Hallo Gemeinde,
mall wieder ein Anfänger Problem im WPF. Aktuell habe ich eine Page(002) die im MainWindow(001) in einem Frame dargestellt wird.
Auf der Page(002) ist eine Datagridview die über eine Dataview mit einer Datatable gebunden ist.
Der Prozess startet einen Backroundworker, der einen langwierigen Automatisierten Prozess abarbeitet und die Datatable mit Daten füllt.
Wenn ich nun die die Größe des MainWindow(001) ändere, die srollleisten des DGV verschiebe, oder sonstige äderungen mache, bekomme ich eine Fehlermeldung "Das DGV ist nicht Konsestent und die menge der enthaltenen Daten stimmt nicht überein.".
Wie kann ich ein absturz meines Programms verhindern(Bei Windows Forms hatte ich das Problem nie)?
Anbei der Prozess Code:
Spoiler anzeigen
und der Code der Page
Spoiler anzeigen
Gruß
Spoiler hinzugefügt ~VaporiZed
mall wieder ein Anfänger Problem im WPF. Aktuell habe ich eine Page(002) die im MainWindow(001) in einem Frame dargestellt wird.
Auf der Page(002) ist eine Datagridview die über eine Dataview mit einer Datatable gebunden ist.
Der Prozess startet einen Backroundworker, der einen langwierigen Automatisierten Prozess abarbeitet und die Datatable mit Daten füllt.
Wenn ich nun die die Größe des MainWindow(001) ändere, die srollleisten des DGV verschiebe, oder sonstige äderungen mache, bekomme ich eine Fehlermeldung "Das DGV ist nicht Konsestent und die menge der enthaltenen Daten stimmt nicht überein.".
Wie kann ich ein absturz meines Programms verhindern(Bei Windows Forms hatte ich das Problem nie)?
Anbei der Prozess Code:
VB.NET-Quellcode
- Option Strict On
- Imports System.Data
- Imports System.ComponentModel
- Imports SolidWorks.Interop
- Imports SolidWorks.Interop.swcommands
- Imports SolidWorks.Interop.swconst
- Public Class Main_Instance
- Dim Assembly_Check_Property As Boolean = True
- Dim Part_Check_Property As Boolean = True
- Dim WorkingTable_Property As DataTable
- Dim FileDictionary_Property As Dictionary(Of String, List(Of String))
- Protected Friend WorkingFrame As System.Windows.Controls.Frame
- Protected Friend WithEvents CFC_SQL_Functions As New CFC_SQL_Functions(Me)
- Protected Friend Returning_Admin_Page As Admin_Page
- Private SWFunc_Main_Instance As New SW_Functions_001.Main_Instance
- Private SW_App_Functions As New SW_Functions_001.SW_Application(SWFunc_Main_Instance)
- Private SW_Configuration_Functions As New SW_Functions_001.SW_ConfigurationFunctions(SWFunc_Main_Instance)
- Private SW_CustomProberty_Functions As New SW_Functions_001.SW_CustomProbertyFunctions(SWFunc_Main_Instance)
- Public ReadOnly UserLoginName As String = System.Environment.UserName
- Public WithEvents MainBackWorker As New BackgroundWorker With {.WorkerReportsProgress = True, .WorkerSupportsCancellation = True}
- Public Event ReportProgress(ByVal Counter As Integer)
- Public Event WorkDone()
- Public Event UpdateTable()
- Public Property Assembly_Check As Boolean
- Get
- Return Assembly_Check_Property
- End Get
- Set(value As Boolean)
- Assembly_Check_Property = value
- End Set
- End Property
- Public Property Part_Check As Boolean
- Get
- Return Part_Check_Property
- End Get
- Set(value As Boolean)
- Part_Check_Property = value
- End Set
- End Property
- Public Property WorkingTable As DataTable
- Get
- If WorkingTable_Property Is Nothing Then
- WorkingTable_Property = CFC_SQL_Functions.LoadWorkingTable
- End If
- Return WorkingTable_Property
- End Get
- Set(ByVal Value As DataTable)
- WorkingTable_Property = Value
- End Set
- End Property
- Public Property FileDictionary As Dictionary(Of String, List(Of String))
- Get
- Return FileDictionary_Property
- End Get
- Set(value As Dictionary(Of String, List(Of String)))
- FileDictionary_Property = value
- End Set
- End Property
- Public Sub New(Optional ByVal CheckAssemblys As Boolean = True, Optional ByVal CheckParts As Boolean = True)
- Assembly_Check = CheckAssemblys
- Part_Check = CheckParts
- AddHandler MainBackWorker.DoWork, AddressOf CheckFailureConfiguration
- AddHandler MainBackWorker.RunWorkerCompleted, AddressOf MainBackWorkerCompletet
- AddHandler MainBackWorker.ProgressChanged, AddressOf MainBackWorkerProgressChanged
- End Sub
- Public Sub StartFunctionsWithPage(ByVal ViewingFrame As System.Windows.Controls.Frame)
- Returning_Admin_Page = New Admin_Page(Me)
- WorkingFrame = ViewingFrame
- ViewingFrame.Navigate(Returning_Admin_Page)
- End Sub
- Public Sub StartFolderWork()
- MainBackWorker.RunWorkerAsync()
- End Sub
- Public Sub CancelBCKWorker()
- MainBackWorker.CancelAsync()
- End Sub
- Private Sub CheckFailureConfiguration(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs)
- Dim i As Integer = 0
- Dim swApp As sldworks.ISldWorks = SWFunc_Main_Instance.swApp
- For Each WorkingKey As KeyValuePair(Of String, List(Of String)) In FileDictionary
- i += 1
- Dim Percent As Integer = CInt((100 / FileDictionary.Count) * i)
- Dim swModelDoc As sldworks.IModelDoc2 = SW_App_Functions.OpenModelDoc(WorkingKey.Key)
- If Not swModelDoc Is Nothing Then
- Dim ConfigurationsList As List(Of String) = SW_Configuration_Functions.GetAllMainConfigurationNames(swModelDoc)
- Dim ModelCreatedby As String = ""
- Dim CreationDate As String = ""
- Dim FileName As New System.IO.FileInfo(WorkingKey.Key)
- If ConfigurationsList.Count >= 2 Then
- Dim Model_DS As DataSet = New CheckFailureConfiguration_DTS
- Model_DS.Clear()
- For Each ConfigName As String In ConfigurationsList
- swModelDoc.ShowConfiguration2(ConfigName)
- Model_DS.Tables.Add(CheckFailureConfiguration_DTS.CreateNewConfigTable(ConfigName))
- FeatureCheck(swModelDoc, Model_DS.Tables(ConfigName), FileName.Name)
- If ModelCreatedby = "" Then
- ModelCreatedby = SW_CustomProberty_Functions.GetFieldValues(swModelDoc, "STD_Erstellt_von")
- Else
- ModelCreatedby = ModelCreatedby & "__" & SW_CustomProberty_Functions.GetFieldValues(swModelDoc, "STD_Erstellt_von")
- End If
- If CreationDate = "" Then
- CreationDate = SW_CustomProberty_Functions.GetFieldValues(swModelDoc, "STD_Erstellt_am")
- Else
- CreationDate = SW_CustomProberty_Functions.GetFieldValues(swModelDoc, "STD_Erstellt_am")
- End If
- Next
- Dim Failure As Boolean = CheckTablesFailure(Model_DS)
- SyncLock WorkingTable
- CFC_SQL_Functions.AddNewRow(FileName.Name, "DateiPfad", FileName.DirectoryName, ConfigurationsList.Count, ModelCreatedby, CreationDate, True, CheckTablesFailure(Model_DS), False, Model_DS)
- End SyncLock
- Else
- ModelCreatedby = SW_CustomProberty_Functions.GetFieldValues(swModelDoc, "STD_Erstellt_von")
- CreationDate = SW_CustomProberty_Functions.GetFieldValues(swModelDoc, "STD_Erstellt_am")
- SyncLock WorkingTable
- CFC_SQL_Functions.AddNewRow(FileName.Name, "DateiPfad", FileName.DirectoryName, ConfigurationsList.Count, ModelCreatedby, CreationDate, True, False, False, Nothing)
- End SyncLock
- End If
- SW_App_Functions.CloseDoc(swModelDoc)
- End If
- MainBackWorker.ReportProgress(Percent)
- If MainBackWorker.CancellationPending Then
- Exit For
- End If
- If swApp Is Nothing Then
- swApp = SWFunc_Main_Instance.swApp
- End If
- Next
- End Sub
- Private Sub MainBackWorkerCompletet(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs)
- RaiseEvent WorkDone()
- MessageBox.Show("Bauteile Geprüft!")
- End Sub
- Private Sub MainBackWorkerProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs)
- RaiseEvent ReportProgress(e.ProgressPercentage)
- End Sub
- Private Sub FeatureCheck(ByVal swModelDoc As sldworks.IModelDoc2, ByVal ConfigTable As DataTable, ByVal ParentName As String)
- Dim swFeature As sldworks.Feature = swModelDoc.IFirstFeature
- Do While Not swFeature Is Nothing
- AddNewRowInConfigTable(ConfigTable, swFeature.GetTypeName2(), swFeature.Name, "Boolean", swFeature.IsSuppressed.ToString, ParentName)
- If swModelDoc.GetType = swDocumentTypes_e.swDocPART Then
- SubFeatureCheck(swFeature, ConfigTable, swModelDoc, swFeature.Name)
- End If
- swFeature = swFeature.IGetNextFeature
- Loop
- End Sub
- Private Sub SubFeatureCheck(ByVal swSubFeature As sldworks.IFeature, ByVal ConfigTable As DataTable, ByVal swModelDoc As sldworks.IModelDoc2, ByVal ParentName As String)
- Do While Not swSubFeature Is Nothing
- AddNewRowInConfigTable(ConfigTable, swSubFeature.GetTypeName2(), swSubFeature.Name, "Boolean", swSubFeature.IsSuppressed.ToString, ParentName)
- If swSubFeature.GetTypeName2 = "Sketch" Or swSubFeature.GetTypeName2 = "ProfileFeature" Then CheckallMeasurement(swSubFeature, ConfigTable, swModelDoc, swSubFeature.Name)
- swSubFeature = swSubFeature.IGetNextSubFeature
- Loop
- End Sub
- Private Sub CheckallMeasurement(ByVal swSubFeature As sldworks.IFeature, ByVal ConfigTable As DataTable, ByVal swModelDoc As sldworks.IModelDoc2, ByVal ParentName As String)
- Dim State As Boolean = swSubFeature.Select2(True, 0)
- swModelDoc.EditSketch()
- Dim swDispDimension As sldworks.IDisplayDimension = CType(swSubFeature.GetFirstDisplayDimension, sldworks.IDisplayDimension)
- Do While Not swDispDimension Is Nothing
- Dim swDimension As sldworks.Dimension = swDispDimension.IGetDimension
- AddNewRowInConfigTable(ConfigTable, "Dimension", swDispDimension.GetNameForSelection, "Double", swDimension.Value.ToString, ParentName)
- swDispDimension = CType(swSubFeature.GetNextDisplayDimension(CType(swDispDimension, Object)), sldworks.IDisplayDimension)
- Loop
- swModelDoc.InsertSketch2(False)
- End Sub
- Private Sub AddNewRowInConfigTable(ByVal ConfigTable As DataTable, ByVal TypeName As String, ByVal Name As String, ByVal ValueType As String, ByVal Value As String _
- , ByVal ParentName As String)
- Dim Newrow As DataRow = ConfigTable.NewRow
- Newrow.BeginEdit()
- Newrow("Type") = TypeName
- Newrow("Name") = Name
- Newrow("ValueType") = ValueType
- Newrow("Value") = Value
- Newrow("Failure") = False
- Newrow("Parent") = ParentName
- Newrow.EndEdit()
- ConfigTable.Rows.Add(Newrow)
- End Sub
- Private Function CheckTablesFailure(ByVal Model_DS As DataSet) As Boolean
- Dim ReturningBoolean As Boolean = False
- For Each FirstTable As DataTable In Model_DS.Tables
- For Each SecondTable As DataTable In Model_DS.Tables
- If FirstTable.TableName <> SecondTable.TableName Then
- For Each FirstRow As DataRow In FirstTable.Rows
- Dim FoundRow() As DataRow = SecondTable.Select("Name ='" & FirstRow("Name").ToString & "'")
- For Each SecondRow As DataRow In FoundRow
- If FirstRow("Value").ToString <> SecondRow("Value").ToString Then
- FirstRow.BeginEdit()
- FirstRow("Failure") = True
- FirstRow.EndEdit()
- SecondRow.BeginEdit()
- SecondRow("Failure") = True
- SecondRow.EndEdit()
- ReturningBoolean = True
- End If
- Next
- Next
- End If
- Next
- Next
- Return ReturningBoolean
- End Function
- Private Sub UpdateTable_temp() Handles CFC_SQL_Functions.UpdateTable
- RaiseEvent UpdateTable()
- End Sub
- End Class
und der Code der Page
VB.NET-Quellcode
- Option Strict On
- Imports System.Data
- Imports System.Windows.Forms
- Imports System.Windows.Controls
- Imports System.ComponentModel
- Imports SWPDM_EnterPrise_Functions_001
- Class Admin_Page
- Dim WithEvents CFC_Main_Instance_hnd As Main_Instance
- Dim FilePath As String = ""
- Dim RefreshCounter As Integer = 0
- Private SWPDM_MainFunctions As SWPDM_EnterPrise_Functions_001.Main_Instance
- Private GOKMF_Main_Instance As New GOK_Main_Functions.Main_Instance
- Private GOKMF_MessegaBoxes As New GOK_Main_Functions.GOK_MessegaBoxes(GOKMF_Main_Instance)
- Private GOKMF_FileFunctions As New GOK_Main_Functions.GOK_File_functions(GOKMF_Main_Instance)
- Private GOKMF_DGV_Functions As New GOK_Main_Functions.GOK_Datagridview_Functions(GOKMF_Main_Instance)
- Private SourceView As DataView
- 'Private Bindingview As BindingListCollectionView
- Dim WithEvents MainBackWorker As New BackgroundWorker With {.WorkerReportsProgress = True, .WorkerSupportsCancellation = True}
- Public Sub New(ByVal CFC_Main_Instance As Main_Instance)
- InitializeComponent()
- CFC_Main_Instance_hnd = CFC_Main_Instance
- SourceView = CFC_Main_Instance_hnd.WorkingTable.DefaultView
- ''Bindingview = New BindingListCollectionView(SourceView)
- End Sub
- Private Sub Admin_Page_Loaded(sender As Object, e As EventArgs) Handles Me.Loaded
- SourceView = CFC_Main_Instance_hnd.WorkingTable.DefaultView
- Me.DGR_001.ItemsSource = SourceView
- SWPDM_MainFunctions = New SWPDM_EnterPrise_Functions_001.Main_Instance()
- Me.CMB_SourceSelect.Items.Add("DateiPfad")
- Me.CMB_FilterSelect.Items.Add("Filter...")
- Me.CMB_FilterSelect.Items.Add("SQL Filter Text...")
- Me.CMB_FilterSelect.Items.Add("Fehler Anzeigen")
- For Each VaultName As String In SWPDM_MainFunctions.VaultList
- Me.CMB_SourceSelect.Items.Add(VaultName)
- Next
- Me.BTN_Assem_Check_Click(Nothing, Nothing)
- Me.BTN_Part_Check_Click(Nothing, Nothing)
- End Sub
- Private Sub Admin_Page_SizeChanged(sender As Object, e As SizeChangedEventArgs) Handles Me.SizeChanged
- Me.Border_01.Width = Me.ActualWidth
- End Sub
- Private Sub BTN_FolderSelecteion_Click(sender As Object, e As RoutedEventArgs) Handles BTN_FolderSelecteion.Click
- Dim OpenFileDialog As FolderBrowserDialog = New FolderBrowserDialog
- Dim Result As DialogResult = OpenFileDialog.ShowDialog()
- If Result = DialogResult.OK Then
- If OpenFileDialog.SelectedPath <> "C:\Users\" & CFC_Main_Instance_hnd.UserLoginName & "\Desktop" Then
- FilePath = OpenFileDialog.SelectedPath
- Me.TXT_Path.Text = FilePath
- End If
- End If
- End Sub
- Private Sub CMB_SourceSelect_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles CMB_SourceSelect.SelectionChanged
- If CMB_SourceSelect.SelectedIndex = 0 Then
- Me.BTN_FolderSelecteion.IsEnabled = True
- Me.TXT_Path.IsEnabled = True
- Else
- Me.BTN_FolderSelecteion.IsEnabled = False
- Me.TXT_Path.IsEnabled = False
- End If
- End Sub
- Private Sub BTN_Assem_Check_Click(sender As Object, e As RoutedEventArgs) Handles BTN_Assem_Check.Click
- If CFC_Main_Instance_hnd.Assembly_Check = False Then
- CFC_Main_Instance_hnd.Assembly_Check = True
- Me.BTN_Assem_Check.Background = Brushes.LightGray
- Else
- CFC_Main_Instance_hnd.Assembly_Check = False
- Me.BTN_Assem_Check.Background = Brushes.White
- End If
- End Sub
- Private Sub BTN_Part_Check_Click(sender As Object, e As RoutedEventArgs) Handles BTN_Part_Check.Click
- If CFC_Main_Instance_hnd.Part_Check = False Then
- CFC_Main_Instance_hnd.Part_Check = True
- Me.BTN_Part_Check.Background = Brushes.LightGray
- Else
- CFC_Main_Instance_hnd.Part_Check = False
- Me.BTN_Part_Check.Background = Brushes.White
- End If
- End Sub
- Private Sub BTN_Start_Function_Click(sender As Object, e As RoutedEventArgs) Handles BTN_Start_Function.Click
- If Me.CMB_SourceSelect.SelectedIndex = 0 Then
- If FilePath <> "" Then
- Dim FileExtensionList As New List(Of String) From {"sldprt", "sldasm"}
- CFC_Main_Instance_hnd.FileDictionary = GOKMF_FileFunctions.GetFilesInPath(FilePath & "\", FileExtensionList)
- Me.PRGBar_001.Maximum = 100
- Me.PRGBar_001.Value = 0
- Me.BTN_Stop_Function.IsEnabled = True
- Me.BTN_Start_Function.IsEnabled = False
- CFC_Main_Instance_hnd.StartFolderWork()
- Else
- GOKMF_MessegaBoxes.NoPath()
- End If
- Else
- End If
- End Sub
- Private Sub Progressbar(ByVal Counter As Integer) Handles CFC_Main_Instance_hnd.ReportProgress
- Dispatcher.BeginInvoke(New MethodInvoker(Sub() Me.PRGBar_001.Value = Counter))
- End Sub
- Private Sub BTN_Stop_Function_Click(sender As Object, e As RoutedEventArgs) Handles BTN_Stop_Function.Click
- CFC_Main_Instance_hnd.CancelBCKWorker()
- Me.BTN_Stop_Function.IsEnabled = False
- Me.BTN_Start_Function.IsEnabled = True
- Me.PRGBar_001.Value = 0
- RefreshCounter = 0
- End Sub
- Private Sub AllPartsChecked() Handles CFC_Main_Instance_hnd.WorkDone
- Me.BTN_Stop_Function.IsEnabled = False
- Me.BTN_Start_Function.IsEnabled = True
- Me.PRGBar_001.Value = 0
- RefreshCounter = 0
- Changecolor()
- End Sub
- Private Sub Changecolor()
- End Sub
- Private Sub RefreshDGR() Handles CFC_Main_Instance_hnd.UpdateTable
- Dispatcher.BeginInvoke(New MethodInvoker(Sub() Me.DGR_001.Items.Refresh()))
- End Sub
- End Class
Gruß
Spoiler hinzugefügt ~VaporiZed
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „VaporiZed“ ()