473,326 Members | 2,114 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,326 software developers and data experts.

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 1190
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
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
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
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?
4
by: TS | last post by:
When i try to access the page class or parent properties inside a server control that is nested in another server control, they are null. I don't even call CreateChildControls for the parent...
2
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
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
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
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
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....
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.