Link to home
Start Free TrialLog in
Avatar of hatem72
hatem72

asked on

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

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
Avatar of lorelogic
lorelogic

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.
Avatar of hatem72

ASKER


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
ASKER CERTIFIED SOLUTION
Avatar of Sancler
Sancler

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hatem72

ASKER


Yes Sancler ... MyItem class works fine and there is many functions and subs and all works fine.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hatem72

ASKER


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 .