Click here to Skip to main content
15,886,873 members
Home / Discussions / C#
   

C#

 
GeneralRe: plz Pin
Richard MacCutchan27-Feb-14 22:14
mveRichard MacCutchan27-Feb-14 22:14 
AnswerRe: plz PinPopular
Pete O'Hanlon28-Feb-14 0:29
mvePete O'Hanlon28-Feb-14 0:29 
GeneralRe: plz Pin
Wayne Gaylard28-Feb-14 1:59
professionalWayne Gaylard28-Feb-14 1:59 
AnswerRe: plz Pin
Ennis Ray Lynch, Jr.28-Feb-14 5:15
Ennis Ray Lynch, Jr.28-Feb-14 5:15 
QuestionHow to click on a node in treeview and display and edit data in listview Pin
daddy35627-Feb-14 18:14
daddy35627-Feb-14 18:14 
AnswerRe: How to load an xml into a treeview then when clicked on an item shows in listview Pin
BillWoodruff27-Feb-14 21:51
professionalBillWoodruff27-Feb-14 21:51 
AnswerRe: How to click on a node in treeview and display and edit data in listview Pin
BillWoodruff1-Mar-14 14:13
professionalBillWoodruff1-Mar-14 14:13 
AnswerRe: How to click on a node in treeview and display and edit data in listview Pin
BillWoodruff8-Mar-14 4:04
professionalBillWoodruff8-Mar-14 4:04 
Very strange: I just composed a reply to another post from the OP, "daddy356," dated March 3, which had revised code and some questions, and then got a "no permission" error to post that reply, and now, the post I replied to has disappeared !

Well, in case it might be useful: here it is:

Your first code example showed the ListView only being populated with 'inXmlNode items that had no child nodes.

The second code example shows the ListView being populated when the current selected TreeNode is not a root node (Parent == null), and where the selected node has more than 1 child node, in which case, you want to populate the ListView with all first-level child nodes of the SelectedNode.

I wonder if you didn't mean to test for:
C#
tv.SelectedNode.Nodes.Count > 0
If that's the case then you could exclude the nodes you don't want to represent in the ListView by:
C#
// return if root-node, or if the node has no child nodes
if (tv.SelectedNode.Parent == null || tv.SelectedNode.GetNodeCount(false) == 0) return;
Note that the 'false argument to GetNodeCount means it will return the same number as if you executed: SelectedNode.Nodes.Count.

Your code is adding Columns to the ListView, not Items ! Try:
C#
// after you clear the ListView ?
foreach (TreeNode tvNode in tv.SelectedNode.Nodes)
{
    listView1.Items.Add(tvNode.Text);
}
The secret to using the 'symmetric dictionaries trick I described above relies on making sure that each Node and ListViewItem have "matching" cross-references in the two Dictionaries. In the case that you re-populate the ListView, for cross-selection to work you must re-use the existing ListViewItems, not create new ones.

To make that work, you need to do something like this:
C#
// after you clear the ListView
foreach (TreeNode tvNode in tv.SelectedNode.Nodes)
{
    listView1.Items.Add(dctTNodeToLvItm[tvNode]);
}

“The best hope is that one of these days the Ground will get disgusted enough just to walk away ~ leaving people with nothing more to stand ON than what they have so bloody well stood FOR up to now.” Kenneth Patchen, Poet


modified 8-Mar-14 10:14am.

GeneralRe: How to click on a node in treeview and display and edit data in listview Pin
daddy3569-Mar-14 12:04
daddy3569-Mar-14 12:04 
GeneralRe: How to click on a node in treeview and display and edit data in listview Pin
BillWoodruff9-Mar-14 21:04
professionalBillWoodruff9-Mar-14 21:04 
GeneralRe: How to click on a node in treeview and display and edit data in listview Pin
daddy3569-Mar-14 21:19
daddy3569-Mar-14 21:19 
GeneralRe: How to click on a node in treeview and display and edit data in listview Pin
BillWoodruff9-Mar-14 21:41
professionalBillWoodruff9-Mar-14 21:41 
GeneralRe: How to click on a node in treeview and display and edit data in listview Pin
BillWoodruff9-Mar-14 23:28
professionalBillWoodruff9-Mar-14 23:28 
GeneralRe: How to click on a node in treeview and display and edit data in listview Pin
daddy35611-Mar-14 5:38
daddy35611-Mar-14 5:38 
QuestionInsert into sql fails. Pin
Member 1063165027-Feb-14 16:12
Member 1063165027-Feb-14 16:12 
AnswerRe: Insert into sql fails. Pin
ScottM127-Feb-14 20:31
ScottM127-Feb-14 20:31 
AnswerRe: Insert into sql fails. Pin
V.27-Feb-14 20:53
professionalV.27-Feb-14 20:53 
AnswerRe: Insert into sql fails. Pin
Mycroft Holmes28-Feb-14 13:15
professionalMycroft Holmes28-Feb-14 13:15 
GeneralRe: Insert into sql fails. Pin
Member 106409593-Mar-14 19:22
Member 106409593-Mar-14 19:22 
QuestionImage from Database to Button.Image C# Pin
Member 1022824227-Feb-14 4:30
Member 1022824227-Feb-14 4:30 
AnswerRe: Image from Database to Button.Image C# Pin
Richard Andrew x6427-Feb-14 11:57
professionalRichard Andrew x6427-Feb-14 11:57 
AnswerRe: Image from Database to Button.Image C# Pin
Ahmed Bensaid28-Feb-14 6:01
professionalAhmed Bensaid28-Feb-14 6:01 
QuestionDataContractSerializer objects conversion performace improvement Pin
impeham27-Feb-14 2:34
impeham27-Feb-14 2:34 
AnswerRe: DataContractSerializer objects conversion performace improvement Pin
BillWoodruff27-Feb-14 8:00
professionalBillWoodruff27-Feb-14 8:00 
GeneralRe: DataContractSerializer objects conversion performace improvement Pin
impeham27-Feb-14 11:49
impeham27-Feb-14 11:49 

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.