?
Solved

DataGridViewComboBoxColumn Error (Object reference not set to an instance of an object)

Posted on 2007-07-29
6
Medium Priority
?
421 Views
Last Modified: 2012-06-21
Hi,
VB 2005, Windows Forms

Here is my code:

        Dim nColCombo1 As New DataGridViewComboBoxColumn
        With nColCombo1
            .HeaderText = "Item"
            .Name = "Col_ItemID"
            Dim x As String = MyItem.FillItemsGrid(nColCombo1) ' Rise Error
            dataGridView1.Columns.Add(nColCombo1)
        End With

In my class :

   Public Function FillItemsGrid(ByRef cBox As Object, Optional ByVal ProvId As Integer = 0) As String
        Dim Sqls As String
         ...

My Problem is the error was rised when calling the function ( Object reference not set to an instance of an object . )

Thanx in advance
0
Comment
Question by:hatem72
  • 3
  • 2
6 Comments
 
LVL 3

Expert Comment

by:lorelogic
ID: 19588417
I think your problem might be with passing a reference type (object) by reference. Almost always an object should be passed by the default ByVal. You will still be able to change the properties of the object, since ByVal passes a copy of the pointer to the object and not the actual pointer to the object (for reference types such as objects). The danger of passing the original pointer to the object, (ByRef) if not needed is that the method can replace the object with a different instance, which is what I think may be happening.
0
 
LVL 6

Author Comment

by:hatem72
ID: 19588435

First thank u ... i did try to change ByRef -> ByVal   BUT Same Problem

ok is there any way to pass DataGridViewComboBoxColumn to Class ???
instead of my way
0
 
LVL 34

Accepted Solution

by:
Sancler earned 1600 total points
ID: 19588456
I assume MyItem is declared AND instantiated?  E,g, Dim MyItem As New MyClass.  And within scope for the code you show.

Roger
0
Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

 
LVL 6

Author Comment

by:hatem72
ID: 19588463

Yes Sancler ... MyItem class works fine and there is many functions and subs and all works fine.
0
 
LVL 3

Assisted Solution

by:lorelogic
lorelogic earned 400 total points
ID: 19588476
Your way should work. Just add an includes for the System.Wihdows.Forms  to give access to the DataGridViewComboBoxColumn and type your cbox as that, then use the object passed, even ByVal, the members can be accessed on the original object, so you can populate it.
0
 
LVL 6

Author Comment

by:hatem72
ID: 19588497

Hi

Sancler u r right about the problem ... i am sure that is the class is fine but i dont know
how do i miss the NEW keyword ... after ur post i copy the function form the class
to the form and it works ... so i found where the problem is .

lorelogic thank u for ur help ... SORYY there is just 500p to split .
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month15 days, 5 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question