Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / June 2007

Tip: Looking for answers? Try searching our database.

Writing control properties to xml

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John - 25 Jun 2007 03:23 GMT
Hi

I am trying to right all control properties on my form to an xml file. My
complete VB code so far is given at the end below. I have two problems
currently.

1. On the line PropValue = Prop.GetValue(Ctrl) I get the error "Conversion
from type 'Padding' to type 'String' is not valid." when the ctrl is
System.Windows.Forms.ListView and Property is Margin which is of type
Padding and not string. How can I resolve such a situation where property is
not a singel value but a collection of sub values?

2. On line xmlWriter.WriteStartElement(Type) I get the error "Token
StartElement in state Epilog would result in an invalid XML document." when
type is System.Windows.Forms.ListView. How can I resolve such a situation?

Many thanks for your time.

Regards

= Code ==================

Module modUtil

Private xmlWriter As Xml.XmlTextWriter

Public Sub WriteControls(ByVal rootControl As Control)
Dim Prop As PropertyDescriptor
Dim Props As PropertyDescriptorCollection
Dim Ctrl As Control
Dim PropName As String
Dim PropValue As String

WriteXMLStart("c:\contacts_template.xml")

For Each Ctrl In rootControl.Controls
 Props = TypeDescriptor.GetProperties(Ctrl)
 WriteXMLControlStart(Ctrl, Ctrl.GetType().ToString())
 For Each Prop In Props
   If (Prop.IsBrowsable) Then
     PropName = Prop.Name
     PropValue = Prop.GetValue(Ctrl)
     WriteXMLProperty(PropValue, PropName)
   End If
 Next
 WriteXMLControlEnd()
Next
WriteXMLEnd()
End Sub

Public Sub WriteXMLStart(ByVal Filename As String)
 xmlWriter = New Xml.XmlTextWriter(Filename, System.Text.Encoding.UTF8)
 xmlWriter.WriteStartDocument()
End Sub

Public Sub WriteXMLControlStart(ByVal Ctrl As Control, ByVal Type As String)
 xmlWriter.WriteStartElement(Type)
 xmlWriter.WriteAttributeString("Name", Ctrl.Name)
End Sub

Public Sub WriteXMLProperty(ByVal Value As String, ByVal Name As String)
 xmlWriter.WriteStartElement(Name)
 xmlWriter.WriteString(Value)
 xmlWriter.WriteEndElement()
End Sub

Public Sub WriteXMLControlEnd()
 xmlWriter.WriteEndElement()
End Sub

Public Sub WriteXMLEnd()
 xmlWriter.WriteEndDocument()
End Sub

End Module
Marc Gravell - 25 Jun 2007 08:27 GMT
Have you looked at the TypeConverter? i.e.
Prop.Converter.ConvertToInvariantString()? You may also wish to check
CanConvertTo/From

Marc

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.