Hi,
I have a Windows Explorer-like treeview that displays directories. After a
cut/paste operation, I want the treeview to display the folder where the
paste happened. But, I'm running into a problem following the assignment of
the selectednode in the treeview. Here's the relevant code:
// separate the node names
string [] split = mcurrentPath.Sp lit(new Char [] {'\\'});
TreeNode currNode = null;
int currIndex = 0;
// find the Node for this node name
foreach (string s in split)
{
if (currIndex == 0)
// we're on the top-most node
currNode = tvwDirectory.To pNode;
// search the current node's nodes for this text
foreach (TreeNode n in currNode.Nodes)
{
if (n.Text == s)
{
currNode = n;
break;
}
}
currIndex++;
}
tvwDirectory.Be ginUpdate();
tvwDirectory.Se lectedNode = null;
tvwDirectory.No des.Clear();
FilltreeView();
tvwDirectory.Se lectedNode = currNode;
tvwDirectory.Se lectedNode.Expa nd(); <-- this is where I blow up!
tvwDirectory.En dUpdate();
I've looked at currNode using the debugger and it looks OK. But, on the
Expand() I get this error:
System.NullRefe renceException: Object reference not set to an instance of
an object.
Any help will be most appreciated.
Thanks,
--
Dave
remove n_o and s_p_a_m to reply directly 4 12739
Hi, David
curnode cannot be for selection after you clear list of nodes in treeview.
It's not present anymore in treeview.
HTH
Alex
"David Elliott" <David_Elliott@ no_spam_excite. com> wrote in message
news:Xn******** ********@24.93. 43.121... Hi,
I have a Windows Explorer-like treeview that displays directories. After a cut/paste operation, I want the treeview to display the folder where the paste happened. But, I'm running into a problem following the assignment
of the selectednode in the treeview. Here's the relevant code:
// separate the node names string [] split = mcurrentPath.Sp lit(new Char [] {'\\'});
TreeNode currNode = null;
int currIndex = 0;
// find the Node for this node name foreach (string s in split) { if (currIndex == 0) // we're on the top-most node currNode = tvwDirectory.To pNode;
// search the current node's nodes for this text foreach (TreeNode n in currNode.Nodes) { if (n.Text == s) { currNode = n; break; } } currIndex++; }
tvwDirectory.Be ginUpdate(); tvwDirectory.Se lectedNode = null; tvwDirectory.No des.Clear(); FilltreeView(); tvwDirectory.Se lectedNode = currNode; tvwDirectory.Se lectedNode.Expa nd(); <-- this is where I blow up! tvwDirectory.En dUpdate();
I've looked at currNode using the debugger and it looks OK. But, on the Expand() I get this error: System.NullRefe renceException: Object reference not set to an instance of an object.
Any help will be most appreciated.
Thanks,
-- Dave
remove n_o and s_p_a_m to reply directly
David Elliott wrote: I have a Windows Explorer-like treeview that displays directories. After a cut/paste operation, I want the treeview to display the folder where the paste happened. But, I'm running into a problem following the assignment of the selectednode in the treeview. Here's the relevant code:
// separate the node names string [] split = mcurrentPath.Sp lit(new Char [] {'\\'});
TreeNode currNode = null;
int currIndex = 0;
// find the Node for this node name foreach (string s in split) { if (currIndex == 0) // we're on the top-most node currNode = tvwDirectory.To pNode;
// search the current node's nodes for this text foreach (TreeNode n in currNode.Nodes) { if (n.Text == s) { currNode = n; break; } } currIndex++; }
tvwDirectory.Be ginUpdate(); tvwDirectory.Se lectedNode = null; tvwDirectory.No des.Clear();
^^^^^^^
this will clear all nodes. So whatever value currNode is pointing to, it's
not a node in the tree anymore.
FilltreeView();
^^^^^^^^
Here you add NEW nodes.
tvwDirectory.Se lectedNode = currNode;
^^^^^^^^
Here you're setting the SelectedNode property to a node object that's NOT
part of the tree, as you cleared all.
tvwDirectory.Se lectedNode.Expa nd(); <-- this is where I blow up! tvwDirectory.En dUpdate();
I've looked at currNode using the debugger and it looks OK. But, on the Expand() I get this error: System.NullRefe renceException: Object reference not set to an instance of an object.
of course, it can't find the node in the tree. :)
FB
--
Get LLBLGen Pro, the new O/R mapper for .NET: http://www.llblgen.com
My .NET Blog: http://weblogs.asp.net/fbouma
Microsoft C# MVP
Hi Alex,
Thanks very much. That helped.
Regards,
David
"AlexS" <sa***********@ SPAMsympaticoPL EASE.ca> wrote in
news:OQ******** ******@TK2MSFTN GP09.phx.gbl: Hi, David
curnode cannot be for selection after you clear list of nodes in treeview. It's not present anymore in treeview.
HTH Alex
"David Elliott" <David_Elliott@ no_spam_excite. com> wrote in message news:Xn******** ********@24.93. 43.121... Hi,
I have a Windows Explorer-like treeview that displays directories. After a cut/paste operation, I want the treeview to display the folder where the paste happened. But, I'm running into a problem following the assignment of the selectednode in the treeview. Here's the relevant code:
// separate the node names string [] split = mcurrentPath.Sp lit(new Char [] {'\\'});
TreeNode currNode = null;
int currIndex = 0;
// find the Node for this node name foreach (string s in split) { if (currIndex == 0) // we're on the top-most node currNode = tvwDirectory.To pNode;
// search the current node's nodes for this text foreach (TreeNode n in currNode.Nodes) { if (n.Text == s) { currNode = n; break; } } currIndex++; }
tvwDirectory.Be ginUpdate(); tvwDirectory.Se lectedNode = null; tvwDirectory.No des.Clear(); FilltreeView(); tvwDirectory.Se lectedNode = currNode; tvwDirectory.Se lectedNode.Expa nd(); <-- this is where I blow up! tvwDirectory.En dUpdate();
I've looked at currNode using the debugger and it looks OK. But, on the Expand() I get this error: System.NullRefe renceException: Object reference not set to an instance of an object.
Any help will be most appreciated.
Thanks,
-- Dave
remove n_o and s_p_a_m to reply directly
--
Dave
remove n_o and s_p_a_m to reply directly
Thanks Frans. You are correct on all counts.
I've changed it around a bit and it's working much better now.
Regards,
David
"Frans Bouma [C# MVP]" <pe************ ******@xs4all.n l> wrote in
news:xn******** *******@msnews. microsoft.com: David Elliott wrote: I have a Windows Explorer-like treeview that displays directories. After a cut/paste operation, I want the treeview to display the folder where the paste happened. But, I'm running into a problem following the assignment of the selectednode in the treeview. Here's the relevant code:
// separate the node names string [] split = mcurrentPath.Sp lit(new Char [] {'\\'});
TreeNode currNode = null;
int currIndex = 0;
// find the Node for this node name foreach (string s in split) { if (currIndex == 0) // we're on the top-most node currNode = tvwDirectory.To pNode;
// search the current node's nodes for this text foreach (TreeNode n in currNode.Nodes) { if (n.Text == s) { currNode = n; break; } } currIndex++; }
tvwDirectory.Be ginUpdate(); tvwDirectory.Se lectedNode = null; tvwDirectory.No des.Clear();
^^^^^^^ this will clear all nodes. So whatever value currNode is pointing to, it's not a node in the tree anymore.
FilltreeView();
^^^^^^^^ Here you add NEW nodes.
tvwDirectory.Se lectedNode = currNode;
^^^^^^^^ Here you're setting the SelectedNode property to a node object that's NOT part of the tree, as you cleared all.
tvwDirectory.Se lectedNode.Expa nd(); <-- this is where I blow up! tvwDirectory.En dUpdate();
I've looked at currNode using the debugger and it looks OK. But, on the Expand() I get this error: System.NullRefe renceException: Object reference not set to an instance of an object.
of course, it can't find the node in the tree. :)
FB
--
Dave
remove n_o and s_p_a_m to reply directly This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: meh |
last post by:
I have a treeView that I'm trapping key strokes like below. It works fine as long as I dont define shortcut keys in the Context Menu assigned to the treeView for those keys. Can someone tell me what I'm doing wrong?
private void treeView1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (treeView1.SelectedNode != null)
|
by: yfzhu |
last post by:
I want a filter:
"menu_id = " + treeview1.selectedNode.tag?
why it can not run?
|
by: jyoti ranjan |
last post by:
i have a ie webcontrols treeview in my application. by default treeview is selecting the first node as selected index.
i don't want a default selectednode. how can i get that one . can any body pls respon
i nead to catch selected index change of tree nodes. since it is selecting 1st node as default, it is not posting back if i am trying to select the first one. i could not run the code for 1st node selection. any advice would be...
|
by: mike uk |
last post by:
I'm generating a treeview (in asp.net Page_Load event) by adding nodes
to a treeview control, and then selecting a single node in the tree
using node.Select().
EnableClientScript property is set to true, which prevents any
autopostbacks.
EnableViewState property is set to false, since I'm not interested in
postbacks.
The treeview correctly shows the selected node in the style defined by
|
by: Tiraman :-\) |
last post by:
Hi Everyone,
i have a treeview that look like this.
Node1
nodechild1.1
nodechild1.2
nodechild1.3
Node2
nodechild2.1
| |
by: Bobby Owens |
last post by:
Hi,
I'm current having a problem with the treeview control and multi
threading. The treeview is on a form. A request is then sent to a
server using IP for the data. The data arrives in an event on a
different thread. I have used delegates to allow me to add to the
treeview and it all works fine. I cant however seem to set the
"SelectedNode" property or the treeview. I have tried directly and
also using a delegate. I all cases, the UI...
|
by: Manick |
last post by:
I have a treeview control in which i am reading the data from the database.I am populating the child nodes in the OnSelectedNodeChanged Event.I am getting all the child nodes in the root but i am unable to bind the root to the tree.
Can anyone point out mistake or addition to my code.
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
TreeNode root = TreeView1.SelectedNode;
...
|
by: bsturg21 |
last post by:
Hello,
I have an app that has a custom treeview which inherits the base
treeview class and I am having a problem with the way the treeview is
being redrawn. Each node in the treeview represents a folder, and
this problem began when I added the functionality to have a ghost
image of the folder when it is dragged and dropped to another location
in the treeview. My code to create the ghost image is as follows:
this.NodeToBeDeleted =...
|
by: Spam Catcher |
last post by:
When I set the SelectedNode programmatically, how come the AfteSelect
doesn't fire?
Other controls (i.e. combobox) I believe do fire the SelectedIndexChanged
when you programmatically update the control.
Is this just a quirk of the TreeView?
Thanks.
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |