473,503 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Writing control properties to xml

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
Jun 25 '07 #1
1 967
Have you looked at the TypeConverter? i.e.
Prop.Converter.ConvertToInvariantString()? You may also wish to check
CanConvertTo/From

Marc
Jun 25 '07 #2

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

Similar topics

8
3329
by: deko | last post by:
I'm hoping someone can sanity check my understanding of the Object Model for Forms/Controls. I'm having trouble drilling down into Control properties. First, I have a record set with the...
5
4587
by: Miguel Dias Moura | last post by:
Hello, i am trying to create a .css file with several styles and apply them to the calendar control so i can change the look of: 1. Text Type and Format (Bold, Underline, etc) 2. Background...
4
270
by: Mark Goldin | last post by:
I'd like to create a user control (Label and Text box) and modify every instance of that control when I add it to a web page. How can I do that?
2
1547
by: | last post by:
I want to use codebehind to pass property values to a control that I've embedded INSIDE of a user control. In other words, let's say I have the following: MyPage.aspx ....with the following...
2
4804
by: rn5a | last post by:
Assume that a user control (MyUC.ascx) encapsulates 2 TextBoxes with the IDs 'txt1' & 'txt2' respectively. To use this user control in an ASPX page, the following Register directive will be...
6
1585
by: John | last post by:
Hi I am trying to save settings of controls on my form to a file so I can read them back later and recreate the controls on the form. I have figured out how to go through all controls and get...
1
1192
by: John | last post by:
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 =...
4
1407
by: Claire | last post by:
Hi, Im new at user control writing in dotnet. I've written a simple gradient painted panel control based on the UserControl class. It works reasonably, but the properties arent being persisted....
0
7201
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
7278
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7328
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6988
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7456
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5011
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1510
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.