473,383 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Save FormSettings of MULTIPLE Forms in XML file!? (VB.NET)

Hi,

I found some examples for storing the FormSettings of a Form in an XML-file,
but none of these could match my criteria: What I am looking for is the
possibility to save the FormSettings of multiple Instances of 1 form.

I have a Form frmSource from which I have multiple Instances, each with a
unique Identifier. So when I Load or Close a specific instance, I want to
load or save the Settings (Top, Height, Width, etc) in an XML-file. I need
to find a way to search with the unique Identifier of the Form in the
XML-file.

Anybody had some examples of this? I thought maybe making a DataSet with the
settings stored in it and writing and reading the XML-file fromd the
DataSet? But how do I fill that DataSet than with my FormSettings?

I'm pretty new to XML (and VB.NET also), so any help would be appreciated!
Thanks in advance!!

DraguVaso
Nov 20 '05 #1
2 3105
Create a dataset sounds like a good idea, and then you
could persist this on program shutdown and reopen when the
program opens. You could also define a class that had
properties corresponding to the form attributes you wanted
to keep track of and serialize/ deserialize this when the
program closed/ opened.

With respect to the dataset method you could try the
following:
Add a schema to your project and define a table with
column headings corresponding to the form attributes you
want to record.

Build a dataset based on the above defined schema.

To Add Initialisation Data To DataSet
Dim NewDataRow As DataRow
For Each FormToRecord
MyNewDataRow = MyFormDataSet.Tables(0).NewRow
MyNewDataRow(ColumnIndexes)= PropertyValues
MyFormDataSet.Tables(0).Add(NewRow)
Next

Create a procedures to call from open and close form
events. Example close event is given below:

Sub FormClose(ByVal FormBeingClosed As Form)

Dim EndLoop As Boolean= False
IENumRow = MyFormDataSet.Tables
(0).Rows.GetEnumerator 'Assumes Only One Row
Do While IENumRow.MoveNext Or Not EndLoop
If IENumRow.Current(Index Corresponding to
column containing identifier) = FormBeingClosedID Then
IEnumRow.Current(IndexOfProperty1Column)=
FormBeingClosed.RelevantProperty
EndLoop= True
End If
Loop
'Use The Index To Update The Current DataRow
MyFormDataSet.Tables(0).Row(Count)
on the open and load events for each form.

-----Original Message-----
Hi,

I found some examples for storing the FormSettings of a Form in an XML-file,but none of these could match my criteria: What I am looking for is thepossibility to save the FormSettings of multiple Instances of 1 form.
I have a Form frmSource from which I have multiple Instances, each with aunique Identifier. So when I Load or Close a specific instance, I want toload or save the Settings (Top, Height, Width, etc) in an XML-file. I needto find a way to search with the unique Identifier of the Form in theXML-file.

Anybody had some examples of this? I thought maybe making a DataSet with thesettings stored in it and writing and reading the XML- file fromd theDataSet? But how do I fill that DataSet than with my FormSettings?
I'm pretty new to XML (and VB.NET also), so any help would be appreciated!Thanks in advance!!

DraguVaso
.

Nov 20 '05 #2
I use the class (code bellow) to write keys on app.exe.config thats is
loaded at startup
You can choose under what key you want to store any settings (set Identifier
from de calling routine)
One remark: While developing it writes on app.exe.config but try to not load
setings on the app.config so i'll need to manuallly copy settings on
app.exe.config to app.config to work on IDE
Hope it Helps
Marcos
Form Code:
*****************
Imports System.Configuration
Imports myApp.myUtilities
Public Identifier as Integer
Load....
Me.Width = CType(Reader.GetValue(Identifier.tostring & ".Width",
GetType(System.Int32)), Int32)
end sub

Closing....
Dim Writer As New AppSettingsWriter()
Writer(Identifier.tostring & ".Width") = CStr(Me.Width)
Writer.SaveFile()
end sub

Class:
*****************
Imports System
Imports System.Xml

Namespace myApp.myUtilities
Public Class AppSettingsWriter
Private configFileName As String
Private document As XmlDocument

Public Sub New()
Dim asmy As System.Reflection.Assembly
Dim tempName As String
asmy = System.Reflection.Assembly.GetEntryAssembly()
tempName = asmy.Location
configFileName = tempName & ".config"
document = New XmlDocument()
document.Load(configFileName)
End Sub

Default Public WriteOnly Property Value(ByVal key As String) As String
Set(ByVal Value As String)
Dim Query As String
Dim Node As XmlNode
Dim Root As XmlNode
Dim Attribute1 As XmlNode
Dim Attribute2 As XmlNode

Query = "/configuration/appSettings/add[@key=" & _
Chr(34) & key & Chr(34) & "]"
Node = document.DocumentElement.SelectSingleNode(Query)
If Not Node Is Nothing Then
Node.Attributes.GetNamedItem("value").Value = Value
Else
Node = document.CreateNode(XmlNodeType.Element, "add", "")
Attribute1 = document.CreateNode(XmlNodeType.Attribute, "key", "")
Attribute1.Value = key
Node.Attributes.SetNamedItem(Attribute1)
Attribute2 = document.CreateNode(XmlNodeType.Attribute, "value", "")
Attribute2.Value = Value
Node.Attributes.SetNamedItem(Attribute2)
Query = "/configuration/appSettings"
Root = document.DocumentElement.SelectSingleNode(Query)
If Not Root Is Nothing Then
Root.AppendChild(Node)
Else
Throw New InvalidOperationException("Não pude adicionar o nodo ao
arquivo config")
End If
End If
End Set
End Property

Public Sub SaveFile()
document.Save(configFileName)
End Sub
End Class
End Namespace
"DraguVaso" <pi**********@hotmail.com> escreveu na mensagem
news:HH*********************@phobos.telenet-ops.be...
Hi,

I found some examples for storing the FormSettings of a Form in an XML-file, but none of these could match my criteria: What I am looking for is the
possibility to save the FormSettings of multiple Instances of 1 form.

I have a Form frmSource from which I have multiple Instances, each with a
unique Identifier. So when I Load or Close a specific instance, I want to
load or save the Settings (Top, Height, Width, etc) in an XML-file. I need
to find a way to search with the unique Identifier of the Form in the
XML-file.

Anybody had some examples of this? I thought maybe making a DataSet with the settings stored in it and writing and reading the XML-file fromd the
DataSet? But how do I fill that DataSet than with my FormSettings?

I'm pretty new to XML (and VB.NET also), so any help would be appreciated!
Thanks in advance!!

DraguVaso

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Suresh Kumaran | last post by:
Hi Everyone, I have an application in the following order. Form 1 - User Enters Part Number. After certain basic validation against the file, Form 2 is show with details pertaining to the...
2
by: MJ | last post by:
i have form1 and form2, form1 has a picturebox which i wish to make it accessible to other forms after form2 perform some drawing, it need to call form1.picbox.invalidate() to refresh the picbox,...
1
by: Don | last post by:
hi in the past (vb 5.0) is used to create applications with multiple forms. i would hide and/or show the appropriate form depending on user input. now i'm using vb.net (still getting used to it)...
1
by: john sutor | last post by:
I have a main form in a project that launches other forms. How do I ensure that the same form does not get launched twice without killing the orignal form. I other words I need a method to manage...
8
by: TJS | last post by:
what are folks doing to get around limitation of one server form per page ?
6
by: Davids | last post by:
this was impossible to implement on old ASP, is it the same for .Net?
4
by: Mike Kim | last post by:
Hi all, In VB6, you can display multiple forms together at design time. how do you do that in vs.net? as a default, vs.net has a group of tabs and only allow to see one at a time unless you add...
10
by: SHPsalm139 | last post by:
We have an Access 2K application that uses multiple forms. We currently hardcode the release number in a label on each form but this gets tedious to do each time there's a new release. I thought...
5
by: c676228 | last post by:
Hi everyone, my colleagues are thinking about have three insurance plans on one asp page: I simplify the plan as follow: text box:number of people plan1 plan2 plan3
3
by: Yehia A.Salam | last post by:
hello, I have to deal with the weird limitation of asp.net, as I need to have multiple forms on my page, well three at least actually, one for the login, one for the search engine, and another...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.