Click here to Skip to main content
15,889,874 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to close a socket which is already open Pin
N a v a n e e t h6-Feb-08 19:58
N a v a n e e t h6-Feb-08 19:58 
GeneralRe: How to close a socket which is already open Pin
AkmalSyed6-Feb-08 23:04
AkmalSyed6-Feb-08 23:04 
GeneralRe: How to close a socket which is already open Pin
sindhutiwari6-Feb-08 23:29
sindhutiwari6-Feb-08 23:29 
GeneralRe: How to close a socket which is already open Pin
Jamman6-Feb-08 23:57
Jamman6-Feb-08 23:57 
GeneralRe: How to close a socket which is already open Pin
Jamman7-Feb-08 0:16
Jamman7-Feb-08 0:16 
GeneralRe: How to close a socket which is already open Pin
sindhutiwari7-Feb-08 0:31
sindhutiwari7-Feb-08 0:31 
GeneralRe: How to close a socket which is already open Pin
Jamman7-Feb-08 1:16
Jamman7-Feb-08 1:16 
Generalwant a help in the code...... [modified] Pin
samidhas6-Feb-08 19:24
samidhas6-Feb-08 19:24 
static void Main()
{
Application.Run(new Form1());
}

private System.Windows.Forms.GroupBox grpbox;
XPathDocument dom;
XmlDocument doc;
XPathNavigator nav;
XPathExpression expr;
XPathNodeIterator iterator;
int cnt=0;
Label lbl;
TextBox txt;
OpenFileDialog dlg;
TreeNode newTreeNode,rootnode,parentnode;
string text;
int i;
//int cnt = e.Node.GetNodeCount(false);
//string filename;

private void Form1_Load(object sender, System.EventArgs e)
{
//label1.Text = "File Path";
//label1.SetBounds(8, 8, 50, 20);

//filename = Application.StartupPath + "\\Sample.xml";
//textBox1.Text= filename;
//textBox1.SetBounds(64, 8, 256, 20);
button1.Text = "Populate the TreeView with XML";
button1.SetBounds(8, 20, 200, 20);
treeXml.Height = 600;
treeXml.Width = 400;
grpbox = new GroupBox();
grpbox.Height = 600;
grpbox.Width = 400;
grpbox.SetBounds(500, 2, 700, 600);
grpbox.Visible = true;
grpbox.Dock.Equals(Right);
grpbox.Show();
this.Controls.Add(grpbox);

//dom = new XPathDocument(dlg.FileName);



}
// it will acess the xml file into treeview

private void ConvertXmlNodeToTreeNode(XmlNode xmlNode,
TreeNodeCollection treeNodes)
{

TreeNode newTreeNode = treeNodes.Add(xmlNode.Name);

switch (xmlNode.NodeType)
{
case XmlNodeType.ProcessingInstruction:
case XmlNodeType.XmlDeclaration:
newTreeNode.Text = "<?" + xmlNode.Name + " " +
xmlNode.Value + "?>";
break;
case XmlNodeType.Element:
if (xmlNode.Name.ToLower().Equals("node") == true)
{
newTreeNode.Text = "<" + xmlNode.Attributes["label"].Value.ToString() + ">";
}
else
newTreeNode.Text = "<" + xmlNode.Name + ">";
break;
case XmlNodeType.Attribute:

newTreeNode.Text = xmlNode.Name;

// newTreeNode.Text = "ATTRIBUTE: " + xmlNode.Name;
break;
case XmlNodeType.Text:
case XmlNodeType.CDATA:
newTreeNode.Text = xmlNode.Value;
break;
case XmlNodeType.Comment:
newTreeNode.Text = "<!--" + xmlNode.Value + "-->";
break;
}

if (xmlNode.Attributes != null)
{
foreach (XmlAttribute attribute in xmlNode.Attributes)
{
ConvertXmlNodeToTreeNode(attribute, newTreeNode.Nodes);
}
}
foreach (XmlNode childNode in xmlNode.ChildNodes)
{
ConvertXmlNodeToTreeNode(childNode, newTreeNode.Nodes);
}
}
// this is an event on which text box is created...


private void treeXml_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{

cnt = e.Node.GetNodeCount(false);
grpbox.Controls.Clear();

for ( i = 0; i < cnt; i++)
{
Label lbl= new Label();
TextBox txt = new TextBox();

//lbl.Name="lbl"+i;
//lbl.Text="lbl"+i;
lbl.Text = e.Node.Text+i;
txt.Name="txt"+i;
txt.Text=txt.Name;

//txt.Text=e.Node.Text+i;
lbl.Left = 200;
lbl.Top = 200 * i;
txt.Left = 250;
txt.Top = 200 * i;
lbl.Show();
txt.Show();
grpbox.Controls.Add(txt);
grpbox.Controls.Add(lbl);



}
}

// this will open an6y xml file stored at your pc.

private void button1_Click(object sender, System.EventArgs e)
{
XmlDocument doc = new XmlDocument();
OpenFileDialog dlg = new OpenFileDialog();
treeXml.Nodes.Clear();
dlg.Title = "Open XML File";
dlg.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*" ;
if (dlg.ShowDialog() == DialogResult.OK)
{
//imgPhoto.Image = new Bitmap(dlg.OpenFile());
doc.Load(dlg.OpenFile());
}

dlg.Dispose();
ConvertXmlNodeToTreeNode(doc, treeXml.Nodes);
treeXml.Nodes[0].ExpandAll();

}
// insert a node

on this button click i want to a node in tree and thje value or string which is in the text box should add to the new treenode....
but this is not wornking,
private void button2_Click(object sender, System.EventArgs e ,TextBox txt)
{

TreeNode rootnode = treeXml.Nodes[0];
TreeNode parentnode = rootnode.Nodes[0];
newTreeNode = new TreeNode(txt.Text);
treeXml.SelectedNode.Nodes.Add(newTreeNode);
// if( treeXml.SelectedNode != null
parentnode = treeXml.SelectedNode;
parentnode.Nodes.Add(new TreeNode(txt.Text));





}

plz help me in this code.

modified on Thursday, February 07, 2008 1:30:10 AM

GeneralRe: want a help in the code...... Pin
Guffa6-Feb-08 20:47
Guffa6-Feb-08 20:47 
GeneralLocalization of Control : Pin
Nadia Monalisa6-Feb-08 18:01
Nadia Monalisa6-Feb-08 18:01 
GeneralRe: Localization of Control : Pin
Abhijit Jana6-Feb-08 20:35
professionalAbhijit Jana6-Feb-08 20:35 
QuestionHow to work with XML effeciently Pin
Richard Blythe6-Feb-08 17:43
Richard Blythe6-Feb-08 17:43 
AnswerRe: How to work with XML effeciently Pin
N a v a n e e t h6-Feb-08 19:10
N a v a n e e t h6-Feb-08 19:10 
GeneralRe: How to work with XML effeciently Pin
Richard Blythe7-Feb-08 5:47
Richard Blythe7-Feb-08 5:47 
AnswerRe: How to work with XML effeciently Pin
Vikram A Punathambekar6-Feb-08 19:23
Vikram A Punathambekar6-Feb-08 19:23 
GeneralRe: How to work with XML effeciently Pin
N a v a n e e t h6-Feb-08 19:27
N a v a n e e t h6-Feb-08 19:27 
GeneralRe: How to work with XML effeciently Pin
Vikram A Punathambekar6-Feb-08 19:34
Vikram A Punathambekar6-Feb-08 19:34 
GeneralRe: How to work with XML effeciently Pin
N a v a n e e t h6-Feb-08 19:40
N a v a n e e t h6-Feb-08 19:40 
AnswerRe: How to work with XML effeciently Pin
Pete O'Hanlon6-Feb-08 23:15
mvePete O'Hanlon6-Feb-08 23:15 
QuestionHow to open explore on click of a button Pin
nilam24776-Feb-08 17:39
nilam24776-Feb-08 17:39 
GeneralRe: How to open explore on click of a button Pin
D i x y6-Feb-08 17:44
D i x y6-Feb-08 17:44 
GeneralRe: How to open explore on click of a button Pin
Richard Blythe6-Feb-08 17:47
Richard Blythe6-Feb-08 17:47 
QuestionC#.NET write to registry at installation time Pin
D i x y6-Feb-08 17:16
D i x y6-Feb-08 17:16 
GeneralRe: C#.NET write to registry at installation time Pin
Richard Blythe6-Feb-08 17:38
Richard Blythe6-Feb-08 17:38 
GeneralRe: C#.NET write to registry at installation time Pin
N a v a n e e t h6-Feb-08 19:17
N a v a n e e t h6-Feb-08 19:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.