Amr Aly
asked on
In which event of a combo box can i Load XML File ?
Hello Experts,
When i use the code below(LoadXmlInv()) in validating events of every combo box my App. hang up the cursor go to the next combo box after many seconds (long time)
I've this Sub to load saved items to a list of combo boxes
And a Sub (SaveInXmlInv())to Save items in a list of combo boxes
And a Sub (RDXmlInv())to Remove duplicate items in a list of combo boxes
in which event of a combo box can i put these 3 Subs(SaveInXmlInv(), LoadXmlInv(), RDXmlInv()).?
Any suggestions will be appreciated
When i use the code below(LoadXmlInv()) in validating events of every combo box my App. hang up the cursor go to the next combo box after many seconds (long time)
I've this Sub to load saved items to a list of combo boxes
Sub LoadXmlInv()
''##For Sorting the items in the combo box and in the same time loading the Xml file
cbxMedH1.Items.AddRange(XElement.Load(Application.StartupPath + "\Investigations.xml").
<Invest>.Select(Function(n) n.Value).OrderBy(Function(s) s).ToArray())
cbxMedH2.Items.AddRange(XElement.Load(Application.StartupPath + "\Investigations.xml").
<Invest>.Select(Function(n) n.Value).OrderBy(Function(s) s).ToArray())
cbxMedH3.Items.AddRange(XElement.Load(Application.StartupPath + "\Investigations.xml").
<Invest>.Select(Function(n) n.Value).OrderBy(Function(s) s).ToArray())
cbxSurH1.Items.AddRange(XElement.Load(Application.StartupPath + "\Investigations.xml").
<Invest>.Select(Function(n) n.Value).OrderBy(Function(s) s).ToArray())
cbxSurH2.Items.AddRange(XElement.Load(Application.StartupPath + "\Investigations.xml").
<Invest>.Select(Function(n) n.Value).OrderBy(Function(s) s).ToArray())
cbxSurH3.Items.AddRange(XElement.Load(Application.StartupPath + "\Investigations.xml").
<Invest>.Select(Function(n) n.Value).OrderBy(Function(s) s).ToArray())
cbxGynH1.Items.AddRange(XElement.Load(Application.StartupPath + "\Investigations.xml").
<Invest>.Select(Function(n) n.Value).OrderBy(Function(s) s).ToArray())
cbxGynH2.Items.AddRange(XElement.Load(Application.StartupPath + "\Investigations.xml").
<Invest>.Select(Function(n) n.Value).OrderBy(Function(s) s).ToArray())
cbxGynH3.Items.AddRange(XElement.Load(Application.StartupPath + "\Investigations.xml").
<Invest>.Select(Function(n) n.Value).OrderBy(Function(s) s).ToArray())
cbxDrugH1.Items.AddRange(XElement.Load(Application.StartupPath + "\Investigations.xml").
<Invest>.Select(Function(n) n.Value).OrderBy(Function(s) s).ToArray())
cbxDrugH2.Items.AddRange(XElement.Load(Application.StartupPath + "\Investigations.xml").
<Invest>.Select(Function(n) n.Value).OrderBy(Function(s) s).ToArray())
cbxDrugH3.Items.AddRange(XElement.Load(Application.StartupPath + "\Investigations.xml").
<Invest>.Select(Function(n) n.Value).OrderBy(Function(s) s).ToArray())
cbxLD.Items.AddRange(XElement.Load(Application.StartupPath + "\Investigations.xml").
<Invest>.Select(Function(n) n.Value).OrderBy(Function(s) s).ToArray())
cbxLC.Items.AddRange(XElement.Load(Application.StartupPath + "\Investigations.xml").
<Invest>.Select(Function(n) n.Value).OrderBy(Function(s) s).ToArray())
cbxHPOC.Items.AddRange(XElement.Load(Application.StartupPath + "\Investigations.xml").
<Invest>.Select(Function(n) n.Value).OrderBy(Function(s) s).ToArray())
cbxGL.Items.AddRange(XElement.Load(Application.StartupPath + "\Investigations.xml").
<Invest>.Select(Function(n) n.Value).OrderBy(Function(s) s).ToArray())
cbxPuls.Items.AddRange(XElement.Load(Application.StartupPath + "\Investigations.xml").
<Invest>.Select(Function(n) n.Value).OrderBy(Function(s) s).ToArray())
cbxBP.Items.AddRange(XElement.Load(Application.StartupPath + "\Investigations.xml").
<Invest>.Select(Function(n) n.Value).OrderBy(Function(s) s).ToArray())
cbxWeight.Items.AddRange(XElement.Load(Application.StartupPath + "\Investigations.xml").
<Invest>.Select(Function(n) n.Value).OrderBy(Function(s) s).ToArray())
cbxBodyBuilt.Items.AddRange(XElement.Load(Application.StartupPath + "\Investigations.xml").
<Invest>.Select(Function(n) n.Value).OrderBy(Function(s) s).ToArray())
cbxChtH.Items.AddRange(XElement.Load(Application.StartupPath + "\Investigations.xml").
<Invest>.Select(Function(n) n.Value).OrderBy(Function(s) s).ToArray())
cbxHdNe.Items.AddRange(XElement.Load(Application.StartupPath + "\Investigations.xml").
<Invest>.Select(Function(n) n.Value).OrderBy(Function(s) s).ToArray())
cbxExt.Items.AddRange(XElement.Load(Application.StartupPath + "\Investigations.xml").
<Invest>.Select(Function(n) n.Value).OrderBy(Function(s) s).ToArray())
cbxFunL.Items.AddRange(XElement.Load(Application.StartupPath + "\Investigations.xml").
<Invest>.Select(Function(n) n.Value).OrderBy(Function(s) s).ToArray())
cbxScars.Items.AddRange(XElement.Load(Application.StartupPath + "\Investigations.xml").
<Invest>.Select(Function(n) n.Value).OrderBy(Function(s) s).ToArray())
cbxEdema.Items.AddRange(XElement.Load(Application.StartupPath + "\Investigations.xml").
<Invest>.Select(Function(n) n.Value).OrderBy(Function(s) s).ToArray())
cbxUS.Items.AddRange(XElement.Load(Application.StartupPath + "\Investigations.xml").
<Invest>.Select(Function(n) n.Value).OrderBy(Function(s) s).ToArray())
End Sub
And a Sub (SaveInXmlInv())to Save items in a list of combo boxes
And a Sub (RDXmlInv())to Remove duplicate items in a list of combo boxes
in which event of a combo box can i put these 3 Subs(SaveInXmlInv(), LoadXmlInv(), RDXmlInv()).?
Any suggestions will be appreciated
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In order to answer your question I would need to see the methods SaveInXmlInv(), LoadXmlInv(), RDXmlInv() and where they are called from. Please post those part of the code.
What do you mean you lost the ComboBox's?
ASKER
i've many (LOTS) of combo boxes
You stated this, "I've lots of combo boxes", what does that mean.
Also please provide the code requested.
Also please provide the code requested.
ASKER
this code for remove duplicates
and this code for saving
Sub RDXmlInv()
Dim fileName1 As String = "Investigations.xml"
Dim xdoc1 As XDocument = XDocument.Load(fileName1)
' Find the duplicate nodes in the XML document
Dim results = (From n In xdoc1.Descendants("Invset")
Group n By Item = n.Element("Name").Value.ToLower() Into itemGroup = Group
Where itemGroup.Count > 1
From i In itemGroup.Skip(1)
Select i).ToList()
' Remove the duplicates from xdoc
results.ForEach(Sub(d) d.Remove())
' Save the modified xdoc to the file system
xdoc1.Save(fileName1)
End Sub
and this code for saving
Sub SaveInXmlPatNames()
''Writing XML content...
Dim xmldoc As XmlDocument = New XmlDocument()
xmldoc.Load(Directory.GetCurrentDirectory & "\PatNames.xml")
With xmldoc.SelectSingleNode("/dataroot").CreateNavigator().AppendChild()
.WriteStartElement("Names")
.WriteElementString("Name", cbxPatName.Text)
.WriteEndElement()
.Close()
End With
With xmldoc.SelectSingleNode("/dataroot").CreateNavigator().AppendChild()
.WriteStartElement("Names")
.WriteElementString("Name", cbxSearch.Text)
.WriteEndElement()
.Close()
End With
With xmldoc.SelectSingleNode("/dataroot").CreateNavigator().AppendChild()
.WriteStartElement("Names")
.WriteElementString("Name", cbxHusband.Text)
.WriteEndElement()
.Close()
End With
With xmldoc.SelectSingleNode("/dataroot").CreateNavigator().AppendChild()
.WriteStartElement("Names")
.WriteElementString("Name", cbxAddress.Text)
.WriteEndElement()
.Close()
End With
xmldoc.Save(Directory.GetCurrentDirectory & "\PatNames.xml")
End Sub
three subs are in validating event of every combo box in the form
ASKER
I'm so sorry sir, we used to use this word (lots of combo boxes) equal to (a lot of combo boxes) and also equal to (many combo boxes)
Can you please post one of the ComboBox Validating event code as well, I am sure they are all the same code.
ASKER
Sub SaveInXmlInv()
''Writing XML content...
Dim xmldoc As XmlDocument = New XmlDocument()
xmldoc.Load(Directory.GetCurrentDirectory & "\Investigations.xml")
With xmldoc.SelectSingleNode("/dataroot").CreateNavigator().AppendChild()
.WriteStartElement("Invest")
.WriteElementString("Name", cbxMedH1.Text)
.WriteEndElement()
.Close()
End With
With xmldoc.SelectSingleNode("/dataroot").CreateNavigator().AppendChild()
.WriteStartElement("Invest")
.WriteElementString("Name", cbxMedH2.Text)
.WriteEndElement()
.Close()
End With
With xmldoc.SelectSingleNode("/dataroot").CreateNavigator().AppendChild()
.WriteStartElement("Invest")
.WriteElementString("Name", cbxMedH3.Text)
.WriteEndElement()
.Close()
End With
With xmldoc.SelectSingleNode("/dataroot").CreateNavigator().AppendChild()
.WriteStartElement("Invest")
.WriteElementString("Name", cbxSurH1.Text)
.WriteEndElement()
.Close()
End With
With xmldoc.SelectSingleNode("/dataroot").CreateNavigator().AppendChild()
.WriteStartElement("Invest")
.WriteElementString("Name", cbxSurH2.Text)
.WriteEndElement()
.Close()
End With
With xmldoc.SelectSingleNode("/dataroot").CreateNavigator().AppendChild()
.WriteStartElement("Invest")
.WriteElementString("Name", cbxSurH3.Text)
.WriteEndElement()
.Close()
End With
With xmldoc.SelectSingleNode("/dataroot").CreateNavigator().AppendChild()
.WriteStartElement("Invest")
.WriteElementString("Name", cbxGynH1.Text)
.WriteEndElement()
.Close()
End With
With xmldoc.SelectSingleNode("/dataroot").CreateNavigator().AppendChild()
.WriteStartElement("Invest")
.WriteElementString("Name", cbxGynH2.Text)
.WriteEndElement()
.Close()
End With
With xmldoc.SelectSingleNode("/dataroot").CreateNavigator().AppendChild()
.WriteStartElement("Invest")
.WriteElementString("Name", cbxGynH3.Text)
.WriteEndElement()
.Close()
End With
With xmldoc.SelectSingleNode("/dataroot").CreateNavigator().AppendChild()
.WriteStartElement("Invest")
.WriteElementString("Name", cbxDrugH1.Text)
.WriteEndElement()
.Close()
End With
With xmldoc.SelectSingleNode("/dataroot").CreateNavigator().AppendChild()
.WriteStartElement("Invest")
.WriteElementString("Name", cbxDrugH2.Text)
.WriteEndElement()
.Close()
End With
With xmldoc.SelectSingleNode("/dataroot").CreateNavigator().AppendChild()
.WriteStartElement("Invest")
.WriteElementString("Name", cbxDrugH3.Text)
.WriteEndElement()
.Close()
End With
With xmldoc.SelectSingleNode("/dataroot").CreateNavigator().AppendChild()
.WriteStartElement("Invest")
.WriteElementString("Name", cbxLC.Text)
.WriteEndElement()
.Close()
End With
With xmldoc.SelectSingleNode("/dataroot").CreateNavigator().AppendChild()
.WriteStartElement("Invest")
.WriteElementString("Name", cbxLD.Text)
.WriteEndElement()
.Close()
End With
With xmldoc.SelectSingleNode("/dataroot").CreateNavigator().AppendChild()
.WriteStartElement("Invest")
.WriteElementString("Name", cbxHPOC.Text)
.WriteEndElement()
.Close()
End With
With xmldoc.SelectSingleNode("/dataroot").CreateNavigator().AppendChild()
.WriteStartElement("Invest")
.WriteElementString("Name", cbxGL.Text)
.WriteEndElement()
.Close()
End With
With xmldoc.SelectSingleNode("/dataroot").CreateNavigator().AppendChild()
.WriteStartElement("Invest")
.WriteElementString("Name", cbxPuls.Text)
.WriteEndElement()
.Close()
End With
With xmldoc.SelectSingleNode("/dataroot").CreateNavigator().AppendChild()
.WriteStartElement("Invest")
.WriteElementString("Name", cbxBP.Text)
.WriteEndElement()
.Close()
End With
With xmldoc.SelectSingleNode("/dataroot").CreateNavigator().AppendChild()
.WriteStartElement("Invest")
.WriteElementString("Name", cbxWeight.Text)
.WriteEndElement()
.Close()
End With
With xmldoc.SelectSingleNode("/dataroot").CreateNavigator().AppendChild()
.WriteStartElement("Invest")
.WriteElementString("Name", cbxBodyBuilt.Text)
.WriteEndElement()
.Close()
End With
With xmldoc.SelectSingleNode("/dataroot").CreateNavigator().AppendChild()
.WriteStartElement("Invest")
.WriteElementString("Name", cbxChtH.Text)
.WriteEndElement()
.Close()
End With
With xmldoc.SelectSingleNode("/dataroot").CreateNavigator().AppendChild()
.WriteStartElement("Invest")
.WriteElementString("Name", cbxHdNe.Text)
.WriteEndElement()
.Close()
End With
With xmldoc.SelectSingleNode("/dataroot").CreateNavigator().AppendChild()
.WriteStartElement("Invest")
.WriteElementString("Name", cbxEdema.Text)
.WriteEndElement()
.Close()
End With
With xmldoc.SelectSingleNode("/dataroot").CreateNavigator().AppendChild()
.WriteStartElement("Invest")
.WriteElementString("Name", cbxFunL.Text)
.WriteEndElement()
.Close()
End With
With xmldoc.SelectSingleNode("/dataroot").CreateNavigator().AppendChild()
.WriteStartElement("Invest")
.WriteElementString("Name", cbxScars.Text)
.WriteEndElement()
.Close()
End With
With xmldoc.SelectSingleNode("/dataroot").CreateNavigator().AppendChild()
.WriteStartElement("Invest")
.WriteElementString("Name", cbxExt.Text)
.WriteEndElement()
.Close()
End With
With xmldoc.SelectSingleNode("/dataroot").CreateNavigator().AppendChild()
.WriteStartElement("Invest")
.WriteElementString("Name", cbxUS.Text)
.WriteEndElement()
.Close()
End With
xmldoc.Save(Directory.GetCurrentDirectory & "\Investigations.xml")
End Sub
ASKER
Private Sub cbxHPOC_Validating(sender As Object, e As System.ComponentModel.Canc elEventArg s) Handles cbxHPOC.Validating
If cbxPatName.Text <> "" Then
btnSave_Click(Nothing, Nothing)
End If
SaveInXmlInv()
RDXmlInv()
LoadXmlInv()
End Sub
If cbxPatName.Text <> "" Then
btnSave_Click(Nothing, Nothing)
End If
SaveInXmlInv()
RDXmlInv()
LoadXmlInv()
End Sub
ASKER
When i comment (LoadXmlInv()) my App. work well
From the looks of it you are saving to many different XML files and using Linq To XML in one part of your code and in the other parts are using XmlDocument.
Is it possible to zip the complete project up and a sample XML document so I can see first hand what the issue is?
Is it possible to zip the complete project up and a sample XML document so I can see first hand what the issue is?
ASKER
As you wish sir
ASKER
This is the link, I'm pleased that you help me sir
https://mega.nz/#!axFxmCgT!3WKMR5EqhhFhHkjmMmh8bzvjNzjvysy964jOpcRYtjI
https://mega.nz/#!axFxmCgT!3WKMR5EqhhFhHkjmMmh8bzvjNzjvysy964jOpcRYtjI
The file you are trying to download is no longer available.
This could be due to the following reasons:
The file has been removed because of a ToS/AUP violation.
Invalid URL - the link you are trying to access does not exist
The file has been deleted by the user.
This could be due to the following reasons:
The file has been removed because of a ToS/AUP violation.
Invalid URL - the link you are trying to access does not exist
The file has been deleted by the user.
ASKER
this link without key
https://mega.nz/#!n1FGCBBC
and this is the decrepted key
!3WKMR5EqhhFhHkjmMmh8bzvjN zjvysy964j OpcRYtjI
https://mega.nz/#!n1FGCBBC
and this is the decrepted key
!3WKMR5EqhhFhHkjmMmh8bzvjN
ASKER
I think this will work
https://mega.nz/#!z8MimSBC!3WKMR5EqhhFhHkjmMmh8bzvjNzjvysy964jOpcRYtjI
https://mega.nz/#!z8MimSBC!3WKMR5EqhhFhHkjmMmh8bzvjNzjvysy964jOpcRYtjI
ASKER
Did it work sir ?
both links work
Hi Amr;
I attempted to compile and run you project but am finding lots of errors that I can not get Form1/frm1 to open. For example in the database you call one of the tables Gyn but in select statements in code Gyn2. In another place a table is not retrieved from the database because you have an empty parameter for the select statement. I just to not have the time to go through these.
Is this and older version that you posted because if your is working this one is not.
I attempted to compile and run you project but am finding lots of errors that I can not get Form1/frm1 to open. For example in the database you call one of the tables Gyn but in select statements in code Gyn2. In another place a table is not retrieved from the database because you have an empty parameter for the select statement. I just to not have the time to go through these.
Is this and older version that you posted because if your is working this one is not.
ASKER
Is this and older version that you posted because if your is working this one is not.Excuse me sir i didn't understand.
The tables in the database that i depend on are (in Form1"frm1" 1-Pat , 2-Gyn , 3-Gyn2) and (in Form2"frm2" 1-Visits , 2-VisitDP , 3-Inves , 4-AtFile )
So i've table called "Gyn" and other one called "Gyn2". And really i can open my form1 and i can insert new patients and update them to dgvpatient(in name, address, date of birth, age, husband name) that's from "Pat" table and i checked it a lot of times this is number one. Number two "Gyn" table is also like "Pat" table, I can insert and update data in it without any error.
Number three "Gyn2" table is also like "Pat" and "Gyn" tables, I can insert and update data in it without any error.
But i'm new in VB.Net language and in programming at all, So you are my teacher if you see any error in my App. i will have to solve it by your experience in this field. So that if you want the old version of my App. i'll give you the link to download in order to fix my last version error. My last version is for a Gynoeologist doctor so i've to finish it in any time
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Amr;
If your using the same code that you post then NO. As I stated it was hitting other errors and never was able to display the Form.
If your using the same code that you post then NO. As I stated it was hitting other errors and never was able to display the Form.
ASKER
I'll use your code sir ,
Bay the way, My App. Open normally and i can save and update in the database(I'm using Start Without Debugging in order to catch any error),
I knew that there are some errors ,So i'm here to solve one by one ,with Experts i think every thing will be OK , And my efforts to search and get the information from the web. I do my best sir and i will do my best to become a good programmer
Will your code solve my hang issue or there are many errors prevent that?
Sub LoadXmlInv() '' Read the XML file from disk only once Dim xDoc = XElement.Load(Application.StartupPath + "\Investigations.xml") '' Parse the XML document only once Dim cbElements = xDoc.<Invest>.Select(Function(n) n.Value).ToArray() '' Now fill the ComboBox's cbxMedH1.Items.AddRange(cbElements) cbxMedH2.Items.AddRange(cbElements) cbxMedH3.Items.AddRange(cbElements) ' ... cbxScars.Items.AddRange(cbElements) cbxEdema.Items.AddRange(cbElements) cbxUS.Items.AddRange(cbElements) End Sub
Bay the way, My App. Open normally and i can save and update in the database(I'm using Start Without Debugging in order to catch any error),
I knew that there are some errors ,So i'm here to solve one by one ,with Experts i think every thing will be OK , And my efforts to search and get the information from the web. I do my best sir and i will do my best to become a good programmer
To your question, "Will your code solve my hang issue or there are many errors prevent that?", well the best way to know that is the use of your application and Visual Studio. If your form opens and you can select items from the ComboBox's and they are populated properly then you can assume that problem has been corrected.
ASKER
Hanginig is still there but when i put your code in one combo box every thin is OK,So i Almost done but there one thing before i leave you to your responsibilities ,I'm sorry for inconvenience
Do you think that validating event is the best event or there is another good event?
Thank you sir for your time and efforts towards me
Do you think that validating event is the best event or there is another good event?
Thank you sir for your time and efforts towards me
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you sir again, I used your code by my own way ....By put one separate element of the code in one combo box "in the validating event"
So every thing become so comfortable and the hanging issue disappear.....many thanks to you sir
Could you please take a look of this open question ? I really need your opinion
https://www.experts-exchange.com/questions/29061204/how-to-make-windows-App-open-a-certain-number-of-times-and-after-that-expires-in-VB-Net.html
So every thing become so comfortable and the hanging issue disappear.....many thanks to you sir
Could you please take a look of this open question ? I really need your opinion
https://www.experts-exchange.com/questions/29061204/how-to-make-windows-App-open-a-certain-number-of-times-and-after-that-expires-in-VB-Net.html
ASKER
Realy your code snnipet is more simple than my code but it gave me the same hang up and the same result when i put (LoadXmlInv() in the validating event of every combo box)in my form