473,385 Members | 1,275 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Object Reference not set to an instance of an object

40
I have a treelistview that is populated with parent child. What I'm trying to do is when the user clicks on the parent place the subitems text into a textbox
Expand|Select|Wrap|Line Numbers
  1. TextBox1.Text = treeListView1.SelectedNodes(0).SubItems(4).Text & ""
Which works fine when I click on a parent, But when I click on the first record child I get error Object Reference not set to an instance of an object.

when I click on the second record child I get specified argument was out of range the valid values parmeter name: Index was out of range. Must be non-negative and less then the size of the collection.

Here is the simple code that dont work
Private Sub treeListView1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles treeListView1.Click

Expand|Select|Wrap|Line Numbers
  1. Try
  2. If treeListView1.SelectedNodes(0).SubItems(4).Text Is DBNull.Value Then
  3. TextBox1.Text = ""
  4. Else
  5. TextBox1.Text = treeListView1.SelectedNodes(0).SubItems(4).Text & ""
  6.  
  7. End If
  8. Catch ex As Exception
  9. MsgBox(ex.Message)
  10.  
  11. End Try
  12.  
  13. End Sub
Any Ideas on how I will tell it - if child rec do nothing.

Thanks

Thank You
Oct 17 '07 #1
8 1212
Plater
7,872 Expert 4TB
You should be checking for null and index counts.

Expand|Select|Wrap|Line Numbers
  1. If treeListView1.SelectedNodes(0) != NULL)
  2.  
And I couldn't find a property called SelectedNodes, but you should be checking to make sure there are at least 4 of those too, if you want to avoid the errors.
Oct 17 '07 #2
KA NMC
40
Thanks Plater the reason you dont see selectedNodes is because I'm using a custom control that combines treeview and listview together, so the properties are a mix of the two and new ones I've never seen before but the wording and results are similar to what a treeview or listview would provide. Its like driving a stick for the first time after driving automatic for most of your life. You get the concept but your still not getting it (Bunch of bumps in between).

This is what I've tried
Expand|Select|Wrap|Line Numbers
  1.  If treeListView1.SelectedNodes(0) Is DBNull.Value Then
  2.                 TextBox1.Text = ""
  3.             Else
  4.                 TextBox1.Text = treeListView1.SelectedNodes(0).SubItems(4).Text & ""
  5.             End If
  6.  
But I'm thinking I need to go back a step and check on the data I'm pulling because it does make sense to get this error when clicking on the child
because the child does not have a 4th subitem - it only has two. Maybe I should add two more?


You should be checking for null and index counts.

Expand|Select|Wrap|Line Numbers
  1. If treeListView1.SelectedNodes(0) != NULL)
  2.  
And I couldn't find a property called SelectedNodes, but you should be checking to make sure there are at least 4 of those too, if you want to avoid the errors.
Oct 17 '07 #3
KA NMC
40
Still the same error...I'm stumped...if you have anymore Ideas that will be great.


Thanks Plater the reason you dont see selectedNodes is because I'm using a custom control that combines treeview and listview together, so the properties are a mix of the two and new ones I've never seen before but the wording and results are similar to what a treeview or listview would provide. Its like driving a stick for the first time after driving automatic for most of your life. You get the concept but your still not getting it (Bunch of bumps in between).

This is what I've tried
Expand|Select|Wrap|Line Numbers
  1.  If treeListView1.SelectedNodes(0) Is DBNull.Value Then
  2.                 TextBox1.Text = ""
  3.             Else
  4.                 TextBox1.Text = treeListView1.SelectedNodes(0).SubItems(4).Text & ""
  5.             End If
  6.  
But I'm thinking I need to go back a step and check on the data I'm pulling because it does make sense to get this error when clicking on the child
because the child does not have a 4th subitem - it only has two. Maybe I should add two more?
Oct 17 '07 #4
Shashi Sadasivan
1,435 Expert 1GB
So even during debugging (especially at the second error- which should then show something in the 1st position of the array)
It isint showing anything informationsl?
Oct 17 '07 #5
KA NMC
40
Yup thats correct its not showing anything...I really dont understand...Not surprising because usually the simple things that will get you...

So even during debugging (especially at the second error- which should then show something in the 1st position of the array)
It isint showing anything informationsl?
Oct 18 '07 #6
Plater
7,872 Expert 4TB
Well I guess start at the topmost, and make sure treeListView1 isn't null.
Then work your way down.
Although if you set a breakpoint in there, you should be able to sift through the treeListView1 object in the watch window and see what all is inside it.
Oct 18 '07 #7
KA NMC
40
So I goooffed - I wanted to add the 4th empty column to the child, so thinking 1,2,3,4 - I added two - when I needed to add 3 (0,1,2,3,4) - so I no longer getting the first err Object Reference not set to an instance of an object, but I'm still getting

specified argument was out of range the valid values parmeter name: Index was out of range. Must be non-negative and less then the size
when clicking on the second records child....I dont know about this one...hmmm


But I'm thinking I need to go back a step and check on the data I'm pulling because it does make sense to get this error when clicking on the child
because the child does not have a 4th subitem - it only has two. Maybe I should add two more?
Oct 18 '07 #8
KA NMC
40
I'll give it a shot again...something I'm missing big time

Well I guess start at the topmost, and make sure treeListView1 isn't null.
Then work your way down.
Although if you set a breakpoint in there, you should be able to sift through the treeListView1 object in the watch window and see what all is inside it.
Oct 18 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

28
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
6
by: Martin | last post by:
I'd like to be able to get the name of an object instance from within a call to a method of that same object. Is this at all possible? The example below works by passing in the name of the object...
15
by: Carlos Lozano | last post by:
Hi, What is the right way to create an OCX COM component. The component is already registerred, but can't create an instance. I am using the reference to the interop module created. If I use...
3
by: Adam | last post by:
We have a web site that uses .vb for the web pages and .cs for a class module. We are getting the error in .NET 2.0 and VS 2005 beta 2. It does work with .NET 1.1. When trying to access a page...
4
by: Luke Matuszewski | last post by:
Here are some questions that i am interested about and wanted to here an explanation/discussion: 1. (general) Is the objectness in JavaScript was supported from the very first version of it (in...
12
by: Andrew Poulos | last post by:
With the following code I can't understand why this.num keeps incrementing each time I create a new instance of Foo. For each instance I'm expecting this.num to alert as 1 but keeps incrementing. ...
6
by: Shailen Sukul | last post by:
Observed a weird behaviour with object references. See code listing below: using System; using System.Collections.Generic; using System.Text; namespace PointerExceptionTest { /*
14
by: Philipp Reif | last post by:
Hi all, I've got a little hole in my head concerning references. Here's what I'm trying to do: I'm calling a function, passing the reference of a business object for editing. The function clones...
3
by: User1014 | last post by:
A global variable is really just a property of the "Global Object", so what does that make a function defined in the global context? A method of the Global Object? ...
2
by: Ralph | last post by:
Hi I don't understand why it's not working: function schedule(imTop){ this.tdImagesTop = imTop; } schedule.prototype.selectEl = function() { alert(this.tdImagesTop);
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.