Click here to Skip to main content
15,881,559 members
Home / Discussions / C#
   

C#

 
QuestionRetrieving connection string from app.config Pin
IMC20068-Jun-06 12:03
IMC20068-Jun-06 12:03 
AnswerRe: Retrieving connection string from app.config Pin
Colin Angus Mackay8-Jun-06 12:28
Colin Angus Mackay8-Jun-06 12:28 
QuestionWhy do the GNU/Linux users recommend C#? Pin
X.Cyclop8-Jun-06 11:38
X.Cyclop8-Jun-06 11:38 
AnswerRe: Why do the GNU/Linux users recommend C#? Pin
Colin Angus Mackay8-Jun-06 12:20
Colin Angus Mackay8-Jun-06 12:20 
GeneralRe: Why do the GNU/Linux users recommend C#? Pin
X.Cyclop8-Jun-06 12:27
X.Cyclop8-Jun-06 12:27 
GeneralRe: Why do the GNU/Linux users recommend C#? Pin
Colin Angus Mackay8-Jun-06 12:33
Colin Angus Mackay8-Jun-06 12:33 
QuestionDatabind xml to a treeview Pin
eggie58-Jun-06 10:58
eggie58-Jun-06 10:58 
AnswerRe: Databind xml to a treeview Pin
Koushik Biswas9-Jun-06 7:19
Koushik Biswas9-Jun-06 7:19 
Aha the urgent guy! So now you are back with a different title line.

First of all, do you want only the DATA part of the XML in your tree view? If you go the normal examples shown in MSDN etc, you will get BOTH TAGNAMES AND DATA in your treeview. As you ar repeatedly asking the question, I am assuming that you need ONLY THE DATA (b'coz otherwise you would have altready got your answer from MSDN etc).

Here is the basic idea of how you can do it. The whole code will be too complex to fit in here. First aof all see the MSDN example from (probably your post only): http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=450892&SiteID=1[^].

From that MSDN example, I will modify ONLY THE button1_Click() method. Not the AddNode() method. You have to follow a slightly different approach here:

private void button1_Click(object sender, EventArgs e)
{
try
{
// SECTION 1. Create a DOM Document and load the XML data into it.
XmlDocument dom = new XmlDocument();
dom.Load(Application.StartupPath + "\\Sample.xml");

// SECTION 2. Initialize the TreeView control.
treeView1.Nodes.Clear();

// SECTION 3. Populate the TreeView with the DOM nodes.
if( dom.DocumentElement.Text == null || dom.DocumentElement.Text == "" )
    treeView1.Nodes.Add(new TreeNode(dom.DocumentElement.Name));
else
    treeView1.Nodes.Add(new TreeNode(dom.DocumentElement.Text));

if (dom.DocumentElement.HasChildNodes)
{
    XmlNodeList nodeList = dom.DocumentElement.ChildNodes;
    for(i = 0; i<=nodeList.Count - 1; i++)
    {
        if( ! ( ( nodeList[i].ChildNodes.Count == 1 )
              && ( nodeList[i].InnerXml == nodeList[i].InnerText ) ) )
            AddNode(nodeList[i], treeView1.Nodes[0]);
    }
}

treeView1.ExpandAll();
}
catch (XmlException xmlEx) { MessageBox.Show(xmlEx.Message); }
catch (Exception ex) { MessageBox.Show(ex.Message); }
}


Note: Instead of calling AddNode once (as shown in MSDN example) I am calling it for all the childnodes in a loop. That eliminates 1 layer - your trr view won't have the level 2 tags. But now in the AddNode() method, what do you do? Answer is you have to follow a similar logic.

Note the catch logic:

if( ! ( ( nodeList[i].ChildNodes.Count == 1 )
      && ( nodeList[i].InnerXml == nodeList[i].InnerText ) ) )


That is the important part. What does that do? It filters out the TEXT NODE. That IF condition (if you remove the '!' part) will evaluate TRUE only for a TEXT node.

You will have to use that IF logic in your modified AddNode(). It won't be simple, but it is ceratinly possible with some time and effort, which I cannot spend now. You may have to make the subsequent recursive calls to AddNode in 2 different modes - TEXT node mode and TAG NODE mode. To enable that, you may need to add a parameter to AddNode() method (for teh mode). That should use the fact that there can only be 1 TEXT child node in a XML node. So when you get that, break out. Add the tree node and then call in TAG mode with the newly created tree node as parameter, but the current XML node (not the TEXT node but its parent) as parameter.

I have done such juggleries before, and I am confident that this is just a brain twister.


Koushik Biswas

who else?
QuestionC# speed vs unmanaged C++ Pin
sjdevo3gsr8-Jun-06 10:58
sjdevo3gsr8-Jun-06 10:58 
AnswerRe: C# speed vs unmanaged C++ Pin
Stephan Samuel8-Jun-06 11:31
Stephan Samuel8-Jun-06 11:31 
AnswerRe: C# speed vs unmanaged C++ Pin
leppie8-Jun-06 20:42
leppie8-Jun-06 20:42 
AnswerRe: C# speed vs unmanaged C++ Pin
Robert Rohde8-Jun-06 20:55
Robert Rohde8-Jun-06 20:55 
GeneralRe: C# speed vs unmanaged C++ Pin
Guffa9-Jun-06 3:10
Guffa9-Jun-06 3:10 
QuestionDataGridView grid lines??? Pin
Small Rat8-Jun-06 10:47
Small Rat8-Jun-06 10:47 
AnswerRe: DataGridView grid lines??? Pin
Mairaaj Khan8-Jun-06 21:22
professionalMairaaj Khan8-Jun-06 21:22 
QuestionRegEx help Pin
econner8-Jun-06 9:02
econner8-Jun-06 9:02 
AnswerRe: RegEx help Pin
Dustin Metzgar8-Jun-06 9:06
Dustin Metzgar8-Jun-06 9:06 
GeneralRe: RegEx help Pin
econner8-Jun-06 9:11
econner8-Jun-06 9:11 
GeneralRe: RegEx help Pin
Le centriste8-Jun-06 9:24
Le centriste8-Jun-06 9:24 
GeneralRe: RegEx help Pin
Dustin Metzgar8-Jun-06 9:40
Dustin Metzgar8-Jun-06 9:40 
QuestionHow to get a list of active USB and Floppy-devices? Pin
Martin#8-Jun-06 8:58
Martin#8-Jun-06 8:58 
QuestionRemoving rows depending on date [modified] Pin
Yustme8-Jun-06 8:38
Yustme8-Jun-06 8:38 
AnswerRe: Removing rows depending on date [modified] Pin
Stephan Samuel8-Jun-06 9:50
Stephan Samuel8-Jun-06 9:50 
GeneralRe: Removing rows depending on date [modified] Pin
Yustme8-Jun-06 10:15
Yustme8-Jun-06 10:15 
GeneralRe: Removing rows depending on date [modified] Pin
Stephan Samuel8-Jun-06 10:57
Stephan Samuel8-Jun-06 10:57 

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.