473,385 Members | 1,930 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,385 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 12 '05 #1
1 5847
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 12 '05 #2

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: 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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.