473,399 Members | 3,106 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,399 software developers and data experts.

How to edit a Xml in a UserControl

Hi

I display a xml file with the TreeView control (Windows Forms) on my
MainForm. Now, I would like to be able to edit this xml file (XmlElements)
when I select a node in this TreeView.

For the editing, I have a UserControl with the corresponding controls
(textboxes, buttons, ...).

But I do not know how! :-(

How can I pass the selected XmlNode from the MainForm to the UserControl?
And how can I save any changes that I made in the UserControl? How can I
update the TreeView control after changes?

Thanks and Regards,
andersch
Oct 2 '06 #1
4 1735
Hi Andersch,

To achieve this, it depends on how you apply the XmlDocument to the
TreeView. Since the Windows form tree view doesn't support binding to a
data source, I think you might have added the nodes one by one to the
TreeView. Is it true?

If so, I think you have to specify the identity for each node. You can
define an XPath to search for specific node in the TreeView and in
XmlDocument. When a node is selected in the TreeView, go through its
ancestors to get each node. Then you can use this path to find in your
XmlDocument. When it is modified, change it also in the TreeView. As far as
I can see, this is the only way. I hope any community member can shed some
light on this if they have any better ways.

Kevin Yu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Oct 3 '06 #2
Hi Hevin
I think you might have added the nodes one by one to the TreeView.
Is it true?
Yes, this is true!

So that I can edit the selected node and the corresponding sub-nodes in the
UserControl, I declare the XmlDocument in the MainForm as static public.

public static XmlDocument dom;

In the AfterSelect event, I pass the selected XmlNode to the UserControl:

if (e.Node.Tag is System.Xml.XmlNode)
{
XmlNode xmlNode = (XmlNode)e.Node.Tag;
if (xmlNode.Name == "Account")
{
if (xmlNode.HasChildNodes)
{
//userControl1.SelectedXmlNode = xmlNode;
userControl1.SetXmlNode(xmlNode);
}
}
}

That solutions works now for me.

But I have now an other question. My Xml looks as follows.

<?xml version="1.0" encoding="utf-8"?>
<EasyCrypto.NET name="Root">
<Category name="e-Banking">
<Account name="Bank1">
<Username>Gaga</Username>
<Password>test@Bank1</Password>
<URL>http://www.bank1.com</URL>
<Description>Bank1 e-Banking Account</Description>
</Account>
</Category>
<Category name="Web">
<Account name="hotmail">
<Username>user_hotmail_06</Username>
<Password>test</Password>
<URL>http://www.hotmail.com</URL>
<Description>Hotmail</Description>
</Account>
<Account name="gmail">
<Username>user:gmail</Username>
<Password>test_gmail</Password>
<URL>http://www.gmail.com</URL>
<Description>Gmail</Description>
</Account>
</Category>
</EasyCrypto.NET>
How can I "move" now a XmlNode Account, for example gmail, to an other
category (node Category)?

Thanks and Regards,
andersch
"Kevin Yu [MSFT]" wrote:
Hi Andersch,

To achieve this, it depends on how you apply the XmlDocument to the
TreeView. Since the Windows form tree view doesn't support binding to a
data source, I think you might have added the nodes one by one to the
TreeView. Is it true?

If so, I think you have to specify the identity for each node. You can
define an XPath to search for specific node in the TreeView and in
XmlDocument. When a node is selected in the TreeView, go through its
ancestors to get each node. Then you can use this path to find in your
XmlDocument. When it is modified, change it also in the TreeView. As far as
I can see, this is the only way. I hope any community member can shed some
light on this if they have any better ways.

Kevin Yu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Oct 3 '06 #3
Hi andersch,

To "move" an XmlNode, you have to remove it from its parent using
XmlNode.RemoveChild method. And then add it to the new parent (node
Category) using XmlNode.AppendChild. Since these are done in an Document,
it will be easy and fast. HTH.

Kevin Yu
Microsoft Online Community Support
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Oct 5 '06 #4
Hi Kevin

Thank you for the information...

Regards,
andersch

"Kevin Yu [MSFT]" wrote:
Hi andersch,

To "move" an XmlNode, you have to remove it from its parent using
XmlNode.RemoveChild method. And then add it to the new parent (node
Category) using XmlNode.AppendChild. Since these are done in an Document,
it will be easy and fast. HTH.

Kevin Yu
Microsoft Online Community Support
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Oct 5 '06 #5

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

Similar topics

0
by: Dave T | last post by:
I have a UserControl with a datagrid in it. In a page I have a datagrid with the user control in an itemtemplate in column 7 (base 0). In the user control datagrid's edit item command, I have...
8
by: Raed Sawalha | last post by:
Hi, I have a strange problem with a usercontrol on a page. The usercontrol dispalyes three categories (From a database) when the user clicks a category they see all the products in a shop for...
2
by: Sascha | last post by:
Hi there, I searched carefully through the web before finally deciding to post this message, because I could not find a solution for my problem. Hopefully someone will have a hint or explanation...
41
by: JohnR | last post by:
In it's simplest form, assume that I have created a usercontrol, WSToolBarButton that contains a button. I would like to eventually create copies of WSToolBarButton dynamically at run time based...
12
by: Joe | last post by:
Hello All: Do I have to use the LoadControl method of the Page to load a UserControl? I have a class which contains three methods (one public and two private). The class acts as a control...
9
by: Marcelo Cabrera | last post by:
Hi, I have a user control that in turn creates a bunch of webcontrols dynamically and handles the events these webcontrols raise. It used to work fine on ASP .Net 1.1 but when compiled on 2.0 it...
2
by: Aled Hughes | last post by:
Hi, I have an MFC application that has a CDialog based dialog box that contains a .net UserControl (via DDX_ManagedControl) as well as a native edit control which has the ES_NUMBER style set. Now...
6
by: MeowCow | last post by:
I have created a UserControl that encapsulates a third party data grid. My goal was to create my own DataSource and DataMember properties that forward the binding to the third party grid, then use...
3
by: zhaodapu | last post by:
I derived a panel class: public class DeskPanel : System.Windows.Forms.Panel Now I want to use the visual designer to add controls in MyPanel class. But I noticed that the visual designer...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
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
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...
0
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
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,...

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.