473,652 Members | 3,049 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(C trl) 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.Write StartElement(Ty pe) 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.XmlTextWrit er

Public Sub WriteControls(B yVal rootControl As Control)
Dim Prop As PropertyDescrip tor
Dim Props As PropertyDescrip torCollection
Dim Ctrl As Control
Dim PropName As String
Dim PropValue As String

WriteXMLStart(" c:\contacts_tem plate.xml")

For Each Ctrl In rootControl.Con trols
Props = TypeDescriptor. GetProperties(C trl)
WriteXMLControl Start(Ctrl, Ctrl.GetType(). ToString())
For Each Prop In Props
If (Prop.IsBrowsab le) Then
PropName = Prop.Name
PropValue = Prop.GetValue(C trl)
WriteXMLPropert y(PropValue, PropName)
End If
Next
WriteXMLControl End()
Next
WriteXMLEnd()
End Sub

Public Sub WriteXMLStart(B yVal Filename As String)
xmlWriter = New Xml.XmlTextWrit er(Filename, System.Text.Enc oding.UTF8)
xmlWriter.Write StartDocument()
End Sub

Public Sub WriteXMLControl Start(ByVal Ctrl As Control, ByVal Type As String)
xmlWriter.Write StartElement(Ty pe)
xmlWriter.Write AttributeString ("Name", Ctrl.Name)
End Sub

Public Sub WriteXMLPropert y(ByVal Value As String, ByVal Name As String)
xmlWriter.Write StartElement(Na me)
xmlWriter.Write String(Value)
xmlWriter.Write EndElement()
End Sub

Public Sub WriteXMLControl End()
xmlWriter.Write EndElement()
End Sub

Public Sub WriteXMLEnd()
xmlWriter.Write EndDocument()
End Sub

End Module
Jun 25 '07 #1
1 1196
Have you looked at the TypeConverter? i.e.
Prop.Converter. ConvertToInvari antString()? 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
3352
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 following for a given Form: 1)Container
5
4594
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 Color 3. Foreground Color 4. Border Tickness 5. Border Color
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?
4
2434
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 control until its pre-render event, so i know the parent control is on the page. Any ideas? thanks
2
1552
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 control placed on it... MyUserControl.ascx .... and inside of MyUserControl.ascx, is an instance of .... MyCommercialUploadControl1
2
4817
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 required: <%@ Register TagPrefix="UC" TagName="MyUserCtrl" Src="MyUC.ascx" %> Assuming that the ASPX page doesn't use a code-behind, I can access the properties, events etc. of the user control in the ASPX page in this way (assume that the ASPX page...
6
1598
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 their properties (see code below). What I am not sure is; how and what type of file format I need to save the info to and how to read it back. Would appreciate any help on that. A code snippet would be very much appreciated. Many thanks
1
972
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 = 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...
4
1417
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. Also I want to expose the base Text property as I like how the IDE generates control names automatically. In the short term would someone tell me how to do these. In the long term, has anyone written any articles explaining how to get started on...
0
8367
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8279
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8703
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8589
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6160
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5619
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2703
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 we have to send another system
1
1914
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1591
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.