Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Dim myReader As System.Data.OleDb.OleDbDataReader
myReader = SelectData.ExecuteReader()
While myReader.Read()
str(0) = myReader.GetString(0)
str(1) = myReader.GetString(1)
itm = New ListViewItem(str)
itm.Checked = True   ---> error??
ListView1.Items.Add(itm)

 

In the above code if i write itm.checked=true during runtime i get error. If i ignore the error the item is indeed getting checked.

 

If the itm.checked=false, i am not getting run time error.

 

The runtime error i am getting is "Object reference not set to the instance of the object". Can you please tell me why such error is occuring.

Posted

ListView is making my life hell

 

Dim str(2) as String
Private Sub test_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
ListView_AddCol()
ListView_AddData()
End Sub

Private Sub ListView_AddCol()
       ListView1.Columns.Add("Item ID", 110, HorizontalAlignment.Left)
       ListView1.Columns.Add("Item Desc", 170, HorizontalAlignment.Left)
End Sub

Private Sub ListView_AddData()
        str(0) = "Item 1"
        str(1) = "ABC"
        Dim itm as New ListViewItem
        itm.Checked = True
        ListView1.Items.Add(itm)  
End Sub


Private Sub ListView1_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles ListView1.ItemCheck
       Dim ij1 as Integer   
       ij1 = e.Index
       If ListView1.Items(ij1).Checked = True Then
           ListView1.Items(ij1).Checked = False
       End If
End Sub

 

I am getting run time error when there is ItemCheck Sub and when i set a particular item is set to true during loading.

 

If there is no itemCheck sub it is working fine

 

Can anyone please help me as to why such error is occuring since i am new to programming.

  • *Gurus*
Posted

itm.Checked = True

 

That line itself should not cause an error. I am skeptical that it does. If indeed it does, make a sample application that reproduces the error and send it to Microsoft.

 

Or, just post your whole project here (without binaries) and I'll see what I can do.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted
I want to do some validation depending upon whether the item is checked or unchecked. I think the ListView1_ItemCheck is getting triggered during runtime. Can it be avoided. Due to that i am getting errors.
  • *Gurus*
Posted

Well, you should have something like this to declare your variable and in the ItemCheck event:

 

   Private ignoreListviewChecks As Boolean

   Private Sub ListView1_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles ListView1.ItemCheck
       If ignoreListviewChecks Then Return

       'Perform validation here
   End Sub

 

And whenever you change a listitem's Checked property manually in code, surround the line by setting the variable to true:

 

ignoreListviewChecks = True
myListViewItem.Checked = True
ignoreListviewChecks = False

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

Divil, can you please help me with this code. It will be very helpful.

 

I have written the following sample code. Can you please modify it for me. It is getting triggered during run time.

 

Dim ij as integer
ij = e.Index()

if ListView1.Items(ij).checked=True
        'Do some validation
else 
       ' Do some validation
end if.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...