Click here to Skip to main content
15,893,663 members
Home / Discussions / C#
   

C#

 
Questionrichtextbox Pin
Shanug28-Feb-14 18:34
Shanug28-Feb-14 18:34 
AnswerRe: richtextbox Pin
Tom Marvolo Riddle28-Feb-14 21:58
professionalTom Marvolo Riddle28-Feb-14 21:58 
AnswerRe: richtextbox Pin
Raj Mouli28-Feb-14 22:00
Raj Mouli28-Feb-14 22:00 
QuestionYou can define columns for a temporary DataTable? Pin
Souza-1063377928-Feb-14 8:34
Souza-1063377928-Feb-14 8:34 
AnswerRe: You can define columns for a temporary DataTable? Pin
Mycroft Holmes28-Feb-14 12:59
professionalMycroft Holmes28-Feb-14 12:59 
QuestionC # if statement (parameter read form sql Server DB) Pin
Member 1063374328-Feb-14 8:16
Member 1063374328-Feb-14 8:16 
AnswerRe: C # if statement (parameter read form sql Server DB) Pin
Richard Deeming28-Feb-14 8:27
mveRichard Deeming28-Feb-14 8:27 
GeneralRe: C # if statement (parameter read form sql Server DB) Pin
Member 1063374328-Feb-14 8:36
Member 1063374328-Feb-14 8:36 
GeneralRe: C # if statement (parameter read form sql Server DB) Pin
Member 104046945-Mar-14 21:29
Member 104046945-Mar-14 21:29 
AnswerRe: C # if statement (parameter read form sql Server DB) Pin
ZurdoDev28-Feb-14 10:56
professionalZurdoDev28-Feb-14 10:56 
QuestionMessage Closed Pin
27-Feb-14 20:31
Member 1063210727-Feb-14 20:31 
AnswerRe: plz Pin
V.27-Feb-14 20:46
professionalV.27-Feb-14 20:46 
AnswerRe: plz Pin
Bernhard Hiller27-Feb-14 20:48
Bernhard Hiller27-Feb-14 20:48 
AnswerRe: plz Pin
ScottM127-Feb-14 20:53
ScottM127-Feb-14 20:53 
AnswerRe: plz Pin
GuyThiebaut27-Feb-14 22:01
professionalGuyThiebaut27-Feb-14 22:01 
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 
daddy356 wrote:
help populating to listview
If your goal is to populate the ListView with items linked to only TreeNodes that have no child nodes, then your code looks fine to me. Is there something wrong with the ListView's contents after the tree is constructed ?

How about your goal of synchronizing the ListView with the TreeView ? "click on a node in treeview and display and edit data in listview" can be interpreted a variety of ways, and I'm trying to imagine how that fits in with the state of the ListView after the TreeView is constructed, as shown in your code.

One technique I've used a lot in synchronizing TreeViews and ListViews is to create "symmetric" Dictionaries, like this:
C#
private readonly Dictionary<ListViewItem, TreeNode> dctLvItmToTNode = new Dictionary<ListViewItem, TreeNode>();
private readonly Dictionary<TreeNode, ListViewItem> dctTNodeToLvItm = new Dictionary<TreeNode, ListViewItem>();

// keep track of current selected items
private TreeNode currentNode;
private ListViewItem currentLVItem;

// flag to prevent recursion
private bool dontRecurse;

// synchronization code TreeView<=>ListView selection

private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
    if (dontRecurse) return;

    if (dctTNodeToLvItm.TryGetValue(e.Node, out currentLVItem))
    {
        dontRecurse = true;
        currentLVItem.Selected = true;
        dontRecurse = false;
    }
}

private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
    if (dontRecurse || listView1.SelectedItems.Count == 0) return;

    if (dctLvItmToTNode.TryGetValue(listView1.SelectedItems[0], out currentNode))
    {
        dontRecurse = true;
        treeView1.SelectedNode = currentNode;
        dontRecurse = false;
    }
}
Use of Dictionaries provide fast look-up. Hope this is useful.
“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

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 
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 

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.