Link to home
Start Free TrialLog in
Avatar of Steve Williams
Steve WilliamsFlag for United States of America

asked on

Deserialize xml file, importing data stops when using DoubleClick!

I have a strange issue. I created a bearing calculator tool for my engineering department and have been slowly adding functionality to it as I use it  so it is more user friendly and efficient. When I create a calculation by filling in the form fields, I then save the data to a xml file by Serialization. which works great. Then I created a listbox to help filter out existing calculations by assembly number. When I select the number I need and double click the listbox it should run the LoadData() Sub which Opens the file I selected and then runs a Deserialize Method to import the data back into the input fields so the code and run the calculation again and redisplay the calculations by means of labels. What happens tho is that when I double click the selection in the listbox it only loads portions of the data with everytime I Double click. Before the listbox i just used the OpenFileDialog to open an existing file and it worked without issue. Something in the listbox is stopping this from following thru with the LoadData() Sub.

Here is the Serialization & Deserialization code.

 Private Function SavedXMLFileContents()
        RunCalculations()
        DisplayCalculations()
        Return sFormData
    End Function
    Private Sub tsmiSaveCalc_Click(sender As Object, e As EventArgs) Handles tsmiSaveCalc.Click
        With sfdSaveCalc
            .InitialDirectory = SavedDataDir
            .DefaultExt = "xml"
            .FileName = txtAssemblyNo.Text + "_" + txtNeedleNo.Text + "_" + spnNumberOfRows.Text + " Rows" + "X" + spnNeedlesPerRow.Text
            .ShowDialog()
        End With
        Dim objStreamWriter As New StreamWriter(sfdSaveCalc.FileName)
        Dim CreateXMLContent As New XmlSerializer(SavedXMLFileContents.GetType)
        CreateXMLContent.Serialize(objStreamWriter, SavedXMLFileContents)
        objStreamWriter.Close()
    End Sub
    Private Sub tsmiOpenCalc_Click(sender As Object, e As EventArgs) Handles tsmiOpenCalc.Click
        With ofdOpenCalc
            .InitialDirectory = SavedDataDir
            .ShowDialog()
        End With
        LoadData()
    End Sub
    Public Sub LoadData()
        currentFilter = txtAssemblyNo.Text
        Dim fn As String = lstAssemblyNo.SelectedValue

        Dim serializer As New XmlSerializer(GetType(FormData))
        Dim fs As New FileStream(fn, FileMode.Open)

        Dim reader As XmlReader = XmlReader.Create(fs)
        Dim i As FormData

        i = CType(serializer.Deserialize(reader), FormData)
        fs.Close()

        sFormData = i
        If i.NeedleType = "Flat Ends" Then rbnFlatEndNeedle.Checked = True Else rbnFlatEndNeedle.Checked = False
        If i.NeedleType = "Spherical Ends" Then rbnSphericalEndNeedle.Checked = True Else rbnSphericalEndNeedle.Checked = False

        If i.OuterRingType = "Through Bore" Then rbnThruBore.Checked = True Else rbnThruBore.Checked = False
        If i.OuterRingType = "Pocket Bore" Then rbnPocketType.Checked = True Else rbnPocketType.Checked = False

        spnNumberOfRows.Value = i.NumberOfRows
        spnNeedlesPerRow.Value = i.NeedlesPerRow

        txtNeedleLen.Text = i.NeedleLen
        txtNeedleDia.Text = i.NeedleDia

        If i.MatType = "Steel" Then rbnSteel.Checked = True Else rbnSteel.Checked = False
        If i.MatType = "Stainless Steel" Then rbnSSteel.Checked = True Else rbnSSteel.Checked = False

        txtRadialLoad.Text = i.RadialLoad
        txtSpeed.Text = i.Speed

        txtAssemblyNo.Text = i.AssemblyNo
        txtNeedleNo.Text = i.NeedleNo

        RunCalculations()
        DisplayCalculations()
    End Sub
    Private Sub lstAssemblyNo_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles lstAssemblyNo.MouseDoubleClick
        LoadData()
    End Sub

Open in new window


Not sure if I explained this right or not, if you need other information I'm not showing please let know so I can display it for you. I know from past experience that most people who help me on this stuff do not want to see all 600 lines of my code. I have attached a screenshot of the application and also a sample of the xml file.
C-1994-A_MD-379-6_1-RowsX28.xml
form-pic2.JPG
ASKER CERTIFIED SOLUTION
Avatar of Steve Williams
Steve Williams
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial